As mentioned in the title, I would like to select a column with name "Avg Estimates" in a dataframe. How can I do this by using "$" operator? Thank you!
Asked
Active
Viewed 5,769 times
3
-
7I guess we don't mark duplicates any more. – Rich Scriven Jan 06 '16 at 20:43
-
2@RichardScriven: Nope, there's no reputation to be gained from that. :) – Joshua Ulrich Jan 06 '16 at 20:46
-
@JoshuaUlrich Yes, but then the reputation boost goes to the wrong person – alexwhitworth Jan 06 '16 at 21:06
-
1@RichardScriven, can you easily find the dupe? (I always have trouble searching for dupes where the "key words" are `$` and `[[` ...) – Ben Bolker Jan 06 '16 at 21:46
-
1not *identical* to http://stackoverflow.com/questions/18222286/select-a-data-frame-column-using-and-the-name-of-the-column-in-a-variable but very very close ... – Ben Bolker Jan 06 '16 at 22:15
1 Answers
11
By using `` as in
df$`Avg Estimates`

Julius Vainora
- 47,421
- 9
- 90
- 102
-
9In fact, backticks (\`), single quotes ('), and double quotes (") can all be used. Other options include `'$'(df, 'Avg Estimates')`, `df[['Avg Estimates']]`, and `'[['(df, 'Avg Estimates')`, and `get('Avg Estimates', df)` – Benjamin Jan 06 '16 at 20:34