I have a list of dataframes and I'd like to get column x
from each dataframe as a string.
testing <- list(data.frame(A = "Yes", B = "No"),
data.frame(B = "No", C = "No"),
data.frame(A = "Yes"))
I can print which of the dataframes have a colname
A in them, but I haven't been able to make the connection to subsetting the original testing
lapply(testing, function(x) "A" %in% colnames(x))
[[1]]
A B
1 Yes No
[[2]]
A
1 Yes
Another base option is Filter
out <- Filter(function(x) "A" %in% names(x), testing)
out
#[[1]]
# A B
#1 Yes No
#
#[[2]]
# A
#1 Yes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With