Quantcast

$ operator is invalid for atomic vectors

classic Classic list List threaded Threaded
2 messages Options
Amy
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

$ operator is invalid for atomic vectors

Amy
This post was updated on .
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: $ operator is invalid for atomic vectors

Pete Brecknock
Amy

It would have been helpful if you had sent your R code of how you constructed the sab object.

If you have a data.frame, the subset command you are having trouble with should work fine. See below.

# Working Example
sab = data.frame(group=c('Group A', 'Group A', 'Group C', 'Group B', 'Group C'), gender=c(1,1,1,2,2))
subset(sab, sab$group=='Group A')

Perhaps your data is stored as a matrix? If so, the following code will fail with the error message you experienced.

# Non Working Example
sab2 = matrix(c('Group A', 'Group A', 'Group C', 'Group B', 'Group C',1,1,1,2,2),5,2)
subset(sab2, sab2$group=='Group A')

HTH

Pete
Loading...