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.s...@imail.org 801.408.8111 > -----Original Message----- > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- > project.org] On Behalf Of Abraham Mathew > Sent: Thursday, June 23, 2011 10:01 AM > To: r-help@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@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. ______________________________________________ R-help@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.