Re: [R] question about subseting a dataframe

From: Charles Plessy <>
Date: Sat, 10 May 2008 12:36:47 +0900

Le Fri, May 09, 2008 at 11:23:37PM -0400, Dipankar Basu a écrit :
> > ex <- data.frame(id=id,year=year,x=x)
> > ex1 <- subset(ex[which(ex$id=="A"|ex$id=="B"),])
> > tapply(ex1$x, ex1$id, mean)
> A B C
> 22.5 32.5 NA

Dear Dipankar,

The reason for this behaviour is that the class of ex$id is "factor". You can avoid this by using the I command, like in:

ex <- data.frame(id=I(id),year=year,x=x)

Have a nice day,

Charles Plessy
Wakō, Saitama, Japan

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Sat 10 May 2008 - 03:50:48 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 10 May 2008 - 06:30:36 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive