I have been trying to create a dataframe (df3) based on two other dataframes of different sizes(df1, df2) and the following conditions:
Include in df3 all the rows where: df1$id = df2$id and df1$cond=df2$cond
I tried:
df3<-df1[(df1$id %in% df2$id &
df1$fcond %in% df2$cond),]
But it selects the rows where at least one of the arguments is true, instead of both.
Dummy data:
t<- c(1,2,3,4,5,6,7,8,9,10)
id<-c(1,1,2,2,3,3,4,4,5,5)
cond <- c(1,5,1,1,1,5,1,1)
df1<-data.frame(cbind(t,id,cond))
id <-c(1,4)
cond <-c(1,1)
df2<- data.frame(cbind(id, cond))
Expected output:
t<- c(1,7)
id<-c(1,4)
cond<- c(1,1)
df3< c(t, id, cond)
Any ideas?