I have a list of data frames which looks like this:
df1
col1 col2
house. 10
cat. 5
dog 7
mouse 4
df2
col1 col2
house. 6
apple. 4
dog 8
elephant 3
df3
col1 col2
horse 1
banana 1
dog 8
The desired output would be:
df1. df2. df3
house. 10 6. NA
cat 5 NA. NA
dog 7 8 8
mouse. 4. NA. NA
apple. NA 4. NA
elephant. NA 3. NA
horse. NA. NA. 1
banana. NA. NA. 1
Any suggestion?
I tried to do the following:
list_df<-list(df1,df2,df3)
df_all<-do.call("rbind", list_df)
df_merge<-as.data.frame(unique(df_all$col1))
colnames(df_merge)<-"category"
df_merge$df1 <- with(df_merge, ifelse (category %in% df1$col1,df1$col2,NA))
however, when I add the second data frame I get this error: $ operator is invalid for atomic vectors