[R] Aggregation of data frame with calculations of proportions

Mark Wardle mark at wardle.org
Wed Jun 27 09:44:52 CEST 2007


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



More information about the R-help mailing list