Let’s say I have a data frame called df
and a vector that contains the column names:
df = data.frame(a = 1:10,b = 11:20,c = 21:30)
colnames = c('a','b','c')
Is there a way that is equivalent to doing df$a
to call a specific column, but that would use the names stored in the object colnames
? Something like this:
df$colnames[1]