Re: [R] question about subseting a dataframe

2008-05-09 Thread Charles Plessy
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) > ABC > 22.5 32.5 NA Dear Dipankar, The reason for this behaviour is that the class of ex$id

Re: [R] question about subseting a dataframe

2008-05-09 Thread Yasir Kaheil
you need to redefine the factor on ex1$id.. cast it again as.factor to redefine the levels. Dipankar Basu wrote: > > Hi! > > I am using R version 2.7.0 and am working on a panel dataset read into R > as > a dataframe; I call it "ex". The variables in "ex" are: id year x > > id: a character

Re: [R] question about subseting a dataframe

2008-05-09 Thread ronggui
Because id is a factor in your data frame, and the levels (including "C") is kept when subsetted. Here is one way to get ride of "C". > ex1$id <- factor(ex1$id) > tapply(ex1$x, ex1$id, mean) AB 22.5 32.5 On Sat, May 10, 2008 at 11:23 AM, Dipankar Basu <[EMAIL PROTECTED]> wrote: > Hi! > >

[R] question about subseting a dataframe

2008-05-09 Thread Dipankar Basu
Hi! I am using R version 2.7.0 and am working on a panel dataset read into R as a dataframe; I call it "ex". The variables in "ex" are: id year x id: a character string which identifies the unit year: identifies the time period x: the variable of interest (which might contain NAs). Here is an