Dear all, How can I take a levels from a dataset. For example, data(iris) x.iris <- iris[,1:4] y.iris <- iris[,5]> y.iris[1] setosa setosa setosa setosa setosa setosa [7] setosa setosa setosa setosa setosa setosa .... [139] virginica virginica virginica virginica virginica virginica [145] virginica virginica virginica virginica virginica virginica Levels: setosa versicolor virginica I want like, y.iris level are, [] setosa versicolor virginica Best regards, Muhammad Subianto
On Apr 27, 2005, at 8:21 AM, Muhammad Subianto wrote:> Dear all, > How can I take a levels from a dataset. > For example, > > data(iris) > x.iris <- iris[,1:4] > y.iris <- iris[,5] >> y.iris > [1] setosa setosa setosa setosa setosa setosa > [7] setosa setosa setosa setosa setosa setosa > .... > [139] virginica virginica virginica virginica virginica virginica > [145] virginica virginica virginica virginica virginica virginica > Levels: setosa versicolor virginica > > I want like, > y.iris level are, > [] setosa versicolor virginica >Muhammad, See ?unique and ?factor. Sean
Well... did you look at the help page on factors??? Did you even make a search? The answer is within your question:> levels(iris[,5])[1] "setosa" "versicolor" "virginica" Eric> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of > Muhammad Subianto > Sent: mercredi 27 avril 2005 14:22 > To: R-help at stat.math.ethz.ch > Subject: [R] Take a levels > > > Dear all, > How can I take a levels from a dataset. > For example, > > data(iris) > x.iris <- iris[,1:4] > y.iris <- iris[,5] > > y.iris > [1] setosa setosa setosa setosa setosa setosa > [7] setosa setosa setosa setosa setosa setosa > .... > [139] virginica virginica virginica virginica virginica > virginica [145] virginica virginica virginica virginica > virginica virginica > Levels: setosa versicolor virginica > > I want like, > y.iris level are, > [] setosa versicolor virginica > > Best regards, > Muhammad Subianto > > ______________________________________________ > 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 >
probably you want: levels(y.iris) I hope it helps. Best, Dimitris ---- Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/16/336899 Fax: +32/16/337015 Web: http://www.med.kuleuven.ac.be/biostat/ http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm ----- Original Message ----- From: "Muhammad Subianto" <subianto at gmail.com> To: <R-help at stat.math.ethz.ch> Sent: Wednesday, April 27, 2005 2:21 PM Subject: [R] Take a levels> Dear all, > How can I take a levels from a dataset. > For example, > > data(iris) > x.iris <- iris[,1:4] > y.iris <- iris[,5] >> y.iris > [1] setosa setosa setosa setosa setosa setosa > [7] setosa setosa setosa setosa setosa setosa > .... > [139] virginica virginica virginica virginica virginica > virginica > [145] virginica virginica virginica virginica virginica > virginica > Levels: setosa versicolor virginica > > I want like, > y.iris level are, > [] setosa versicolor virginica > > Best regards, > Muhammad Subianto > > ______________________________________________ > 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 >