24 Jan 2002, 08:10 UTC
[R] Re: your mail
- From
- Ott Toomet siim@obs.ee
- Date
- Thu, 24 Jan 2002 00:10:09 -0800 (PST)
Hi, you have to use tapply(). A small example:
Quoted or forwarded from earlier messages
> region <- c("Atl", "Mount", "Atl")
> state <- c("NY", "AR", "WAS")
> pop <- c(1000, 100, 1000)
> d <- data.frame(region,state,pop)
# note that region and state are coerced to factors by data.frame()
> tapply(d$pop, d$region, sum)
Atl Mount
2000 100
A very similar example was in ,,An introduction to R'' for version 1.1, I
think it is in the current version too.
best wishes,
Ott Toomet
On Wed, 23 Jan 2002, Erin Hodgess wrote:
> Dear R People:
>
> Here is a very simple question, please:
>
> I have a data frame with the state name, state division, and population.
>
> Note: state division is something like Atlantic, Mountain, etc.
>
> I want to produce a table with the state division and the total of the
> populations for the states within that division.
>
> I've been messing with "table" but so far, no luck.
>
> This is R1.3.1, on Windows 98.
>
> thanks in advance!
>
> Sincerely,
> Erin Hodgess
> Associate Professor
> Department of Computer and Mathematical Sciences
> University of Houston - Downtown
> 1 Main Street
> Houston, TX 77002
> mailto: hodgess@uhddx01.dt.uh.edu
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !) To: r-help-request@stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._