Closed duttashi closed 5 years ago
Solution: 1
library(tidverse)
mget(paste0("df", 1:3)) %>%
map(~ .x %>%
pull(Variable)) %>%
reduce(intersect)
Solution: 2
Bind the datasets into a single one, grouped by 'Variable', filter the number of unique groups equal to 3 and extract the 'Variable'
bind_rows(df1, df2, df3, .id = 'grp') %>%
group_by(Variable) %>%
filter(n_distinct(grp) == 3) %>%
distinct(Variable) %>%
pull(Variable)
This question was originally asked on SO
Question: Suppose there are n dataframes (in this case 3). How to extract variables which appear in all n dataframes?
Dataset