我有2个数据帧如下:
MonadPlus
如果T1 $ Artist == C1 $ Artist |,我希望能够对T1进行子集化T1 $ FeatArtist == C1 $艺术家和T1日期发生在C1日期
之后结果应为:
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
我试过了:
T1
Date|Artist|FeatArtist
06-11-1955|UNK|M
06-05-1956|UNK|M
25-11-1956|X|UNK
但没有成功 - 任何想法我怎么能做到这一点?
答案 0 :(得分: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