Re: [R] Aggregation of data frame with calculations of proportions

From: Mark Wardle <mark_at_wardle.org>
Date: Wed, 27 Jun 2007 08:44:52 +0100

Dear Jim,

On 26/06/07, jim holtman <jholtman_at_gmail.com> wrote:
> I think something like this will do it for you.
>
>
>
> set.seed(1)
> n <- 10
> x <- data.frame(a=sample(1:100,n),
> b=sample(1:100,n),d=sample(1:100,n))
> x$a[c(1,5)] <- NA
> x$b[c(7,6,4)] <- NA
> x$d[c(5,8)] <- NA
> x$total <- rowSums(x, na.rm=TRUE)
> x$type <- sample(1:3, n, replace=TRUE)
> by(x, list(x$type), function(z){
> apply(z[,1:3], 2, calc.prevalence, total=z$total)
> })
>
>
> [...SNIP...]
> --
> Jim Holtman
> Cincinnati, OH
> +1 513 646 9390
>
> What is the problem you are trying to solve?

It works perfectly. The problem now is how to send over that beer I owe you!

Many thanks,

Best wishes,

-- 
Dr. Mark Wardle
Clinical research fellow and specialist registrar, Neurology
Cardiff, UK

______________________________________________
R-help_at_stat.math.ethz.ch 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.
Received on Wed 27 Jun 2007 - 07:52:23 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 27 Jun 2007 - 13:32:25 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.