I’ve created 3 vectors:
v1 = c(1,2,3)
v2 = c(11,22,33)
v3 = c(111,222,333)
Then I’ve made a frame from them:
> df = data.frame(vec1 = v1, vec2 = v2, vec3 = v3)
> df
vec1 vec2 vec3
1 1 11 111
2 2 22 222
3 3 33 333
It seems like column names is not automatic now, but vec1, vec2, vec3.
After this I want to get a frame row where vec2 is equal to 11:
> df[vec2 == 11,]
Error in `[.data.frame`(df, vec2 == 11, ) : object 'vec2' not found
But the following code works:
> df[v2 == 11,]
vec1 vec2 vec3
1 1 11 111
I think this is wrong. I don’t understand why R uses old vector names, instead of tags vec1, vec2, vec3.
Is it a bug of my version of R?
R version 2.15.2 (2012-10-26)
Platform: x86_64-apple-darwin12.2.0/x86_64 (64-bit)
Either use:
or
The second one worked because
v2 == 11evaluates toTRUE, FALSE, FALSEand so, the first row was being printed. However,vec2is not a variable that is set. It is a column of adata.frame. So, you’ll have to identify it as such withdf$vec2(or usewith)