I am faced with a problem trying to find the variables in common between all dataframes in a list.
I found this link.
But it does not answer my problem because they are only using the colname
to do the comparison whereas I am interested in the variables within a column.
To begin, I have a list, of data frames, lets call it list1.
>list1
[[1]]
V1 V2 V3
1 "a" 1
2 "b" 9
3 "c" 3
[[2]]
V1 V2 V3
1 "c" 5
2 "d" 4
3 "e" 6
#and so on..... for 22 times
Now, I want to output an array of all the list1[[i]]$V2
variables that are in common between all the dataframe
s. So, If the remaining 20 dataframe
s all look like list1[[2]]
, then the output should be c
; because it would be the only common V2
variable between all the dataframe
s.
I have tried using do.call("rbind", list1)
and using dplyr
to find the common V2
s but I can't seem to figure it out. Also, I know intersect()
can be used in this instance, but using intersect(intersect(intersect....
Seems like a very inefficient approach to the problem and I want to do this operation on other lists as well. Any help would be much appreciated.
Thank you very much,
-Omar.