Here's a way to get to your solution, but it's not very pretty: testdfr <- data.frame(POB=c("Oregon","Oregon","Oregon","New York","California","California"))
nstates <- length(unique(testdfr$POB)) testdfr$ POBR <- c(nstates:1)[table(testdfr$POB)][testdfr$POB] greetings, Remko ------------------------------------------------- Remko Duursma Post-Doctoral Fellow Centre for Plants and the Environment University of Western Sydney Hawkesbury Campus Richmond NSW 2753 Dept of Biological Science Macquarie University North Ryde NSW 2109 Australia Mobile: +61 (0)422 096908 On Fri, Jul 24, 2009 at 8:45 AM, ws<webb.spra...@gmail.com> wrote: > Hi all, > > I am using ACS micro data (PUMS) with one of the columns as a > factor for the place of birth (POBPF). I would like to create > a column (POBR) containing a rank > corresponding to the place of the observation > in the POBPF rankings. For example, > if a person is from Oregon, Oregon is > the most popular Place of Birth, so each > person who came from Oregon should have a 1 > in their POBR. Each row from > California would have POBR 2, etc. > > This way I can subset on the most populous sending > places when doing analyses. > > For the life of me I can't figure this out. > I think some combination of "sort()", > "xtabs()" and "merge()" should work, > but my brain seems to be fried. > > Tx > > ______________________________________________ > 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.