. Advertisement .
..3..
. Advertisement .
..4..
I am new to R and searching a solution for “$ operator is invalid for atomic vectors”. It seems it doesn’t work as expected when I used some suggestions before. This is the script that I ran:
x<-c(1,2)
x
names(x)<- c("bob","ed")
x$ed
The error I’m getting is below:
Error in x$ed : $ operator is invalid for atomic vectors
Please give me the solution for this issue.
There is no mystery here, you’re trying to access vector elements by using $ operator, but this operator does not support to do that. You could simply use [] to access to vector elements instead. For your example, could you try to run as follow?
You can access the
$
help file (see?"$"
)Let’s now check if
x
works recursivelyA recursive object is a list-like structure. A vector is not recursive. It is an atomic object. Let’s see.
You will get an error when you apply
$
to vectors (non-recursive objects). Use[
instead.getElement
can also be used