Skip to content
Prev 248712 / 398506 Next

Problems making subsets with [] or "subset"

Hi Mario,
On Fri, Jan 28, 2011 at 12:27 PM, gaiarrido <gaiarrido at usal.es> wrote:
That should work, assuming you have attached the dataframe containing
the variables in your model. A safer way is to use the data agrument
to aov instead:

model<-aov(intensity~ageandsex*month*zone*year, data=X,
subset=(prevalence=="1"))
Well what is [prevalencia=="1"] indexing? Nothing, which isn't going
to work. You can use

model<-aov(hemogregarinas~edadysexo*mes*zona*ano, data=X[prevalencia=="1" , ])
Well I'm not sure, but I suspect it has something to do with attaching
things, and getting confused about where the data is actually coming
from. This gives the same results:

dat <- data.frame(x=c(1,2,2,1,3,4,2,5,3,20), y =
c(2,1,3,3,2,5,6,4,5,20), z=c(rep(1, 9),2))

attach(dat)
summary(x[z==1])
summary(subset(x, z==1))

so again, not sure why you're getting something different. Try storing
your data in a data.frame, and use the data arguments instead of
attaching it, and see if you get more sensible results.

Best,
Ista