Daer All, I have a factor variable, X with 5 levels. When I type tables(X) it gives me: table(X) 1 2 3 4 5 10 5 0 0 0 How to drop the levels with zeros such that when I will type: table(X) it will give me: table(X) 1 2 10 5 Thank a lot, Bernard --------------------------------- [[alternative HTML version deleted]]
Marc Bernard wrote:> Daer All, > > I have a factor variable, X with 5 levels. When I type tables(X) it gives me: > > table(X) > 1 2 3 4 5 > 10 5 0 0 0 > > How to drop the levels with zeros such that when I will type: > table(X) it will give me: > > table(X) > 1 2 > 10 5table(X[,drop=TRUE]) Uwe Ligges> > Thank a lot, > > Bernard > > > > > --------------------------------- > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Marc Bernard <bernarduse1 at yahoo.fr> writes:> Daer All, > > I have a factor variable, X with 5 levels. When I type tables(X) it gives me: > > table(X) > 1 2 3 4 5 > 10 5 0 0 0 > > How to drop the levels with zeros such that when I will type: > table(X) it will give me: > > table(X) > 1 2 > 10 5table(factor(X)) or table(X[drop=TRUE]) should do it. The latter runs the former, but the intention might be clearer. -- O__ ---- Peter Dalgaard ??ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
Hi On 10 Nov 2005 at 14:32, Marc Bernard wrote: Date sent: Thu, 10 Nov 2005 14:32:35 +0100 (CET) From: Marc Bernard <bernarduse1 at yahoo.fr> To: r-help at stat.math.ethz.ch Subject: [R] Remove levels> Daer All, > > I have a factor variable, X with 5 levels. When I type tables(X) it > gives me: > > table(X) > 1 2 3 4 5 > 10 5 0 0 0 > > How to drop the levels with zeros such that when I will type: > table(X) it will give me:see ?factor table(factor(X)) HTH Petr> > table(X) > 1 2 > 10 5 > > > Thank a lot, > > Bernard > > > > > --------------------------------- > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.htmlPetr Pikal petr.pikal at precheza.cz