Reputation: 7517
Generally, in a list
of data.frame
s (for example below), I was wondering how I could obtain the names of the variables that are repeated 2 or more times (in this example the names would be "AA"
, "BB"
, "CC"
) across the data.frame
s?
r <- list( data.frame( AA = c(2,2,1,1,NA, NA), BB = c(1,1,1,2,2,NA), CC = c(1:5, NA)),
data.frame( AA = c(1,NA,3,1,NA,NA), BB = c(1,1,1,2,NA,NA)),
data.frame( AA = c(1,NA,3,1,NA,NA), BB = c(1,1,1,2,2,NA), CC = c(0:4, NA)) )
Upvotes: 1
Views: 346
Reputation: 6234
You could:
unlist
the list to get all column names as a single vector,unique
) duplicate names in the vector using duplicated
.## get names
vec <- names(unlist(r, recursive = FALSE))
## return duplicates
unique(vec[duplicated(vec)])
#> [1] "AA" "BB" "CC"
Upvotes: 2