3:51 AM
To: Cory Nissen
Cc: r-help@stat.math.ethz.ch
Subject: RE: [R] by group problem
Hi
now I understand better what you want
topN.2 - function(data,n=5) data[order(data[,3], decreasing=T),][1:n]
# I presume data is data frame with 3 columns and the third is percent
lapply(split(data,data
Hi
now I understand better what you want
topN.2 - function(data,n=5) data[order(data[,3], decreasing=T),][1:n]
# I presume data is data frame with 3 columns and the third is percent
lapply(split(data,data$state), topN.2)
Regards
Petr
[EMAIL PROTECTED]
Cory Nissen [EMAIL PROTECTED] napsal
Perhaps you want this?
data - NULL
data$state - c(rep(Illinois, 10), rep(Wisconsin, 10))
data$county - c(Adams, Brown, Bureau, Cass, Champaign,
Christian, Coles, De Witt, Douglas, Edgar,
Adams, Ashland, Barron, Bayfield, Buffalo,
Burnett,
See the examples labelled head in the examples section near the bottom of:
http://sqldf.googlecode.com/svn/trunk/man/sqldf.Rd
These show show to do it using order as well as using SQL via sqldf.
On 8/31/07, Cory Nissen [EMAIL PROTECTED] wrote:
I am working with census data. My columns of
That didn't work for me...
Here's some data to help with a solution.
data - NULL
data$state - c(rep(Illinois, 10), rep(Wisconsin, 10))
data$county - c(Adams, Brown, Bureau, Cass, Champaign,
Christian, Coles, De Witt, Douglas, Edgar,
Adams, Ashland, Barron,
Hi, try this:
by(data$percentOld, list(data$state, data$county), FUN=topN)
is this you want?
--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40 S 49° 16' 22 O
On 31/08/2007, Cory Nissen [EMAIL PROTECTED] wrote:
That didn't work for me...
Here's some data to help with a solution.