Re: [R] factor question

2008-07-24 Thread Mark Difford
Hi Edna, Because I am "always" subsetting, I keep the following function handy mydata[] <- lapply(mydata, function(x) if(is.factor(x)) x[,drop=T] else x) This will strip out all factor levels that have been dropped by a previous subsetting operation. For novice users of R (though I am not sugge

Re: [R] factor question

2008-07-24 Thread Henrique Dallazuanna
Try: fac1[3:9][drop=T] On Thu, Jul 24, 2008 at 4:19 PM, Edna Bell <[EMAIL PROTECTED]> wrote: > Hi! > > Suppose I have a factor: > >> fac1 <- factor(rep(c("dog","cat","tree"),c(2,3,4))) >> fac1 > [1] dog dog cat cat cat tree tree tree tree > Levels: cat dog tree >> length(fac1) > [1] 9 > > No

[R] factor question

2008-07-24 Thread Edna Bell
Hi! Suppose I have a factor: > fac1 <- factor(rep(c("dog","cat","tree"),c(2,3,4))) > fac1 [1] dog dog cat cat cat tree tree tree tree Levels: cat dog tree > length(fac1) [1] 9 Now I want to get rid of the dogs: > fac1 <- fac1[3:9] > fac1 [1] cat cat cat tree tree tree tree Levels: cat do