I have 2 dataframes as follows:
我有2个数据帧如下:
C1
Date|Artist
01-11-1955|M
18-01-1956|M
19-04-1956|M
01-05-1956|M
21-11-1956|X
T1
Date|Artist|FeatArtist
06-11-1955|UNK|M
15-01-1956|M|UNK
15-04-1956|UNK|M
06-05-1956|UNK|M
25-11-1956|X|UNK
25-11-1956|M|UNK
I want to be able to subset T1 if the T1$Artist == C1$Artist| T1$FeatArtist == C1$Artist and T1 date happened after C1 Date
如果T1 $ Artist == C1 $ Artist |,我希望能够对T1进行子集化T1 $ FeatArtist == C1 $艺术家和T1日期发生在C1 Date之后
The result should be:
结果应该是:
T1
Date|Artist|FeatArtist
06-11-1955|UNK|M
06-05-1956|UNK|M
25-11-1956|X|UNK
I tried:
t<- T1[which(T1$Artist%in% unique(C1$Artist) | T1$FeatArtist%in% unique(C1$Artist)& T1$Date > max(C1$Date)),]
but didn't work out - any idea how I can achieve this please?
但没有成功 - 任何想法我怎么能实现这一点呢?
1 个解决方案
#1
0
T1$Date=as.Date(strptime(T1$Date,"%d-%m-%Y"))
C1$Date=as.Date(strptime(C1$Date,"%d-%m-%Y"))
e=quote(Date.x>Date.y&Date.x-Date.y<7)
a=subset(merge(T1,C1,by="Artist",all=TRUE),eval(e))
b=subset(merge(T1,C1,by.x="FeatArtist",by.y="Artist",all=TRUE),eval(e))
rbind(a,setNames(b,names(a)),row.names=NULL)[-4]
Artist Date.x FeatArtist
12 X 1956-11-25 UNK
1 M 1955-11-06 UNK
121 M 1956-05-06 UNK
#1
0
T1$Date=as.Date(strptime(T1$Date,"%d-%m-%Y"))
C1$Date=as.Date(strptime(C1$Date,"%d-%m-%Y"))
e=quote(Date.x>Date.y&Date.x-Date.y<7)
a=subset(merge(T1,C1,by="Artist",all=TRUE),eval(e))
b=subset(merge(T1,C1,by.x="FeatArtist",by.y="Artist",all=TRUE),eval(e))
rbind(a,setNames(b,names(a)),row.names=NULL)[-4]
Artist Date.x FeatArtist
12 X 1956-11-25 UNK
1 M 1955-11-06 UNK
121 M 1956-05-06 UNK