Dynamically select dataframe column in R

PHOTO EMBED

Thu Mar 11 2021 14:57:05 GMT+0000 (Coordinated Universal Time)

Saved by @stephenb30 #r

var <- "mpg"
#Doesn't work
mtcars$var
#These both work, but note that what they return is different
# the first is a vector, the second is a data.frame
mtcars[[var]]
mtcars[var]
content_copyCOPY

https://stackoverflow.com/questions/18222286/dynamically-select-data-frame-columns-using-and-a-character-value