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
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
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
3 matches
Mail list logo