[R] accessing elements located after $ symbol

2010-10-05 Thread Lorenzo Cattarino
Hi R-users I am having troubles accessing elements after the $ symbol. Reproducible example: test - data.frame (first=1:10, second=11:20, third=21:30) test$first #this works fine but when I try interest - first test$interest # does not seem to work Could you tell me why that

Re: [R] accessing elements located after $ symbol

2010-10-05 Thread Joshua Wiley
Dear Lorenzo, This is the trade off that comes with convenience. The `$` operator passes its argument directly as I understand it. This is what lets you pass unquoted names that not variables. The way around it is to use the `[` extraction operator. Look at these examples: test[interest] #or

Re: [R] accessing elements located after $ symbol

2010-10-05 Thread Ben Bolker
Joshua Wiley jwiley.psych at gmail.com writes: [snip] Look at these examples: test[interest] #or test[, interest] # but test[first] test[,first] Notice that for `[`, the name of the column _must_ be quoted, or be an object itself. or test[[first]] ; you probably do not want