Hello! If I read ?subset, the workings of the argument drop (to me) seem to imply equivalence of A and B (R 1.9.0): #A dd <- data.frame(rt=rnorm(10), c=factor(gl(2,5))) dd <- subset(dd, c==1) dd$c <- dd$c[, drop=TRUE] table(dd$c) 1 5 #B dd <- data.frame(rt=rnorm(10), c=factor(gl(2,5))) dd <- subset(dd, c==1, drop=TRUE) table(dd$c) 1 2 5 0 So to lose the second level of dd$c, in method B I still need to 'dd$c <- dd$c[, drop=TRUE]', while the manual seems to imply that with the drop argument to subset() this would not be necessary. Could you comment? kind regards, Paul -- Paul Lemmens NICI, University of Nijmegen ASCII Ribbon Campaign /"\ Montessorilaan 3 (B.01.05) Against HTML Mail \ / NL-6525 HR Nijmegen X The Netherlands / \ Phonenumber +31-24-3612648 Fax +31-24-3616066
Paul Lemmens <P.Lemmens at nici.kun.nl> writes:> Hello! > > If I read ?subset, the workings of the argument drop (to me) seem to > imply equivalence of A and B (R 1.9.0): > > #A > dd <- data.frame(rt=rnorm(10), c=factor(gl(2,5))) > dd <- subset(dd, c==1) > dd$c <- dd$c[, drop=TRUE] > table(dd$c) > > 1 > 5 > > > #B > dd <- data.frame(rt=rnorm(10), c=factor(gl(2,5))) > dd <- subset(dd, c==1, drop=TRUE) > table(dd$c) > > 1 2 > 5 0 > > So to lose the second level of dd$c, in method B I still need to 'dd$c > <- > dd$c[, drop=TRUE]', while the manual seems to imply that with the drop > argument to subset() this would not be necessary. > > > Could you comment?Looks like a documentation bug. The actual code ends up doing x[r, vars, drop = drop] and "[.data.frame" will not drop factor levels. I wonder if it ever did... -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
Maybe Matching Threads
- Numbers that look equal, should be equal, but if() doesn't see as equal (repost with code included)
- Accessing columns in data.frame using formula
- is.na(v)<-b (was: Re: Beginner's query - segmentation fault)
- library(car) Anova() and Error-term in aov()
- Cbind warning message