[R] Odp: by group problem
petr.pikal at precheza.cz
Fri Aug 31 15:15:29 CEST 2007
> I am working with census data. My columns of interest are...
> PercentOld - the percentage of people in each county that are over 65
> County - the county in each state
> State - the state in the US
> There are about 3100 rows, with each row corresponding to a county
within a state.
> I want to return the top five "PercentOld" by state. But I want the
> and the Value.
> I tried this...
> topN <- function(column, n=5)
> column <- sort(column, decreasing=T)
> top5PerState <- tapply(data$percentOld, data$STATE, topN)
aggregate(data$PercentOld, list(data$State, data$County), topN)
> But this only returns the value for "percentOld" per state, I also want
> corresponding County.
> I think I'm close, but I just can't get it...
> [[alternative HTML version deleted]]
> R-help at stat.math.ethz.ch mailing list
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help