How to use a string variable to select a data frame column using $ notation [duplicate]

If you have a variable x with a column name in tmp, tmp[,x] or tmp[[x]] are the correct ways to extract it. You cannot get R to treat tmp$x as tmp$"Q5.3". tmp$x will always refer to the item named “x” in “tmp”.

Leave a Comment