[R] Finding the "levels" in a data frame column
Greg Snow
Greg.Snow at imail.org
Thu Jun 23 18:55:46 CEST 2011
Try levels(df$city) or unique(df$city) depending on if it is a factor (default) or character string.
--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Abraham Mathew
> Sent: Thursday, June 23, 2011 10:01 AM
> To: r-help at r-project.org
> Subject: [R] Finding the "levels" in a data frame column
>
> I have a data frame that looks as follows.
>
> df <- data.frame(city=c("Houston", "Houston", "El Paso", "Waco",
> Houston",
> "Plano", "Plano")
>
> What I want to do is get a list of the city values. Currently, when I
> run
> df$city, I get all the values.
>
> I just want to know the four cities that appear.
> So instead of: "Houston", "Houston", "El Paso", "Waco", Houston",
> "Plano",
> "Plano"
>
> I want: "Houston", "El Paso", "Waco", "Plano"
>
>
> I'm running R 2.13 on Ubuntu 10.10
>
>
> Abraham
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list