Suppose I have a factor size with levels "small", "medium" and "large". Then, when I subset this factor:>ss<-size[size!="medium"]to get at the extremes,>levels(ss).... Levels: large medium small The same happens with>subset( size, size!="medium")I understand that the resulting factor inherits the possible levels from its "parent", but I do not see in what that is useful. Intuitively, I would expect that levels(ss) return "small" and "large". For subset(), there might be an option to request inheritance of the number of levels. RenE J.V. Bertin College de France/LPPA 11, place Marcelin Berthelot 75005 Paris, France _________________________________________________________________ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
rjvbertin@hotmail.com writes:> Suppose I have a factor size with levels "small", "medium" and "large". > Then, when I subset this factor: > >ss<-size[size!="medium"] > to get at the extremes, > >levels(ss) > .... > Levels: large medium small > > The same happens with > >subset( size, size!="medium") > > I understand that the resulting factor inherits the possible levels from its > "parent", but I do not see in what that is useful. Intuitively, I would > expect that levels(ss) return "small" and "large". For subset(), there might > be an option to request inheritance of the number of levels.Not a bug (in any sense). Basically, you do need factors with levels that are not present once in a while (we had a tabulation example recently), and it is easier to remove unwanted levels than it is to get the levels back in. E.g.> x[-1][1] medium large Levels: large medium small> x[-1,drop=T][1] medium large Levels: large medium> factor(x[-1])[1] medium large Levels: large medium As for the usefulness, consider this> with(subset(juul,sex==1), table(menarche))numeric(0)> juul$menarche <- factor(juul$menarche) > with(subset(juul,sex==1), table(menarche))menarche 1 2 0 0 -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Wed, 19 Jun 2002 rjvbertin@hotmail.com wrote:> Suppose I have a factor size with levels "small", "medium" and "large". > Then, when I subset this factor: > >ss<-size[size!="medium"] > to get at the extremes, > >levels(ss) > .... > Levels: large medium small > > The same happens with > >subset( size, size!="medium") > > I understand that the resulting factor inherits the possible levels from its > "parent", but I do not see in what that is useful.When you have enough experience you may. Lots of R code relies on it, for a start. It's also essential when predicting a classifcation to know wha the possible values were. That's the whole point of a factor: it's an enumeration type, and one does not change the enumeration on subsetting.> Intuitively, I would > expect that levels(ss) return "small" and "large". For subset(), there might > be an option to request inheritance of the number of levels.There is such an option: [, drop=TRUE]. Please DO NOT use R-bugs to document your intuition. -- Brian D. Ripley, ripley@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> Suppose I have a factor size with levels "small", "medium" and "large". > Then, when I subset this factor: > >ss<-size[size!="medium"] > to get at the extremes, > >levels(ss) > .... > Levels: large medium smallsure, because you didn't change the levels attribute of the factor object ss. And there is no statement in the documentation that subsetting a factor object touches the levels attribute. So why is this a bug? If I remember correctly, there was a dicussion about this issue a few month ago on this list ... Torsten> > The same happens with > >subset( size, size!="medium") > > I understand that the resulting factor inherits the possible levels from its > "parent", but I do not see in what that is useful. Intuitively, I would > expect that levels(ss) return "small" and "large". For subset(), there might > be an option to request inheritance of the number of levels. > > RenE J.V. Bertin > College de France/LPPA > 11, place Marcelin Berthelot > 75005 Paris, France > > _________________________________________________________________ > > > > > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html > Send "info", "help", or "[un]subscribe" > (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._ >-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
rjvbertin@hotmail.com writes:> Suppose I have a factor size with levels "small", "medium" and "large". > Then, when I subset this factor: > >ss<-size[size!="medium"] > to get at the extremes, > >levels(ss) > .... > Levels: large medium smallTry: R> ss <- size[size != "medium", drop=T] R> levels(ss) [1] "large" "small" By the way, this type of question probably belongs in R-help, not R-devel, and you will likely get grief for submitting it as a "bug". -- -- David Brahm (brahm@alum.mit.edu) -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._