Salvo R Salvo R - 10 months ago 101
R Question

R, merge a list of dataframe to find the rows unique for each dataframe

I have a list of different data frame, just a general example:

x <- data_frame(i = c("a","b","c"), j = 1:3)
y <- data_frame(i = c("b","c","d"), k = 4:6)
z <- data_frame(i = c("c","d","a"), l = 7:9)
list(x,y,z)


I want to find the rows that are common in the different couples (xy, yz, xz) and in xyz, and the one there are unique in x, y, z.

I want to find some fast way to code it.

I read other thread here and I find this in a similar question:

list(x,y,z) %>%
Reduce(function(dtf1,dtf2) left_join(dtf1,dtf2,by="i"), .)


And I tried:

list(x,y,z) %>%
Reduce(function(x,y) anti_join(x,y, by="i"), .)


which is giving me back the rows present in x but not in y, meaning that I have write a similar line for each couple and then inner_join the results.

there is a better way?

Answer Source

You need to use:

all<-plyr::join_all(list(x,y,z), "i",type = "full")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download