Hi,

No is the more elegant way


analysis <-

lapply(c("fac1", "fac2"), function(x){

cbind.data.frame(par1.sum= do.call("rbind",lapply(lapply(split(df,
eval(parse(text=x))), "[[", 1), sum)),

par2.mean=do.call("rbind",lapply(lapply(split(df, eval(parse(text=x))),
"[[", 2), mean)),

par2.sd= do.call("rbind",lapply(lapply(split(df, eval(parse(text=x))), "[[",
2), mean)))

})


On 30/10/2007, Antje <[EMAIL PROTECTED]> wrote:
>
> Hello,
>
> unfortunately, I don't know a better subject. I would like to be very
> flexible
> in how to process my data.
> Assume the following dataset:
>
> par1 <- seq(0,1,length.out = 100)
> par2 <- seq(1,100)
> fac1 <- factor(rep(c("group1", "group2"), each = 50))
> fac2 <- factor(rep(c("group3", "group4", "group5", "group6"), each = 25))
>
> df <- data.frame(par1, par2, fac1, fac2)
>
> Now, I would like to calculate e.g. the "sum" for par1 grouping by "fac1"
> and
> the "mean" and "sd" for par2 grouping by "fac1".
>
> I would like to determine this method as a string.
>
> In the end, I would like to have something like this:
>
> fac1.analysis:
>
>       par1.sum    par2.mean     par2.sd
> group1    xxx           xxx         xxx
> group2    xxx           xxx         xxx
>
> fac2.analysis:
>
> ...
>
> Does anybody have any idea how to realize it?
>
> Antje
>
> ______________________________________________
> [email protected] 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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

        [[alternative HTML version deleted]]

______________________________________________
[email protected] 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.

Reply via email to