I have a concatenated string having column names in it:
col_names = paste(c("Age", "Sex", "City", "Name"), collapse=', ')
col_names
[1] "Age, Sex, City, Name"
I also have a data frame=df that has 100s of variables.
How can I select the columns present in my string (col_names) from the df using col_names?
df[names(read.csv(text = col_names))]would work.