[R] $ operator is invalid for atomic vectors

Pete Brecknock Peter.Brecknock at bp.com
Wed Jan 19 01:39:47 CET 2011


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
-- 
View this message in context: http://r.789695.n4.nabble.com/operator-is-invalid-for-atomic-vectors-tp3224224p3224318.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list