Skip to content
Back to formatted view

Raw Message

Message-ID: <971536df0602170013h15e7a1a6kd488a7363ff5246@mail.gmail.com>
Date: 2006-02-17T08:13:29Z
From: Gabor Grothendieck
Subject: Transforming results of the summary function
In-Reply-To: <1140163581.23615.19.camel@localhost.localnet>

Try this:

do.call("rbind", xs)


On 2/17/06, Maciej Blizi??ski <m.blizinski at wit.edu.pl> wrote:
> Hi all,
>
> I have a question about transforming the data from summary function.
> Let's say I have a data frame like this:
>
> > x = data.frame(a = c(rep("lev1", 5), rep("lev2", 5)), b = c(rnorm(5)+2, rnorm(5)))
> > x
>      a          b
> 1  lev1  1.5964765
> 2  lev1  2.2945609
> 3  lev1  3.5285787
> 4  lev1  1.4439838
> 5  lev1  2.2948826
> 6  lev2  1.7063506
> 7  lev2 -0.4042742
> 8  lev2 -1.6485337
> 9  lev2 -1.1163817
> 10 lev2 -0.2023246
>
> I'd like to create quantiles for every level of the "a" column. Looking
> into the documentation, I found the function "by" with which I can
> perform the calculations...
>
> > xs = by(x, x$a, function(x) summary(x$b))
> > xs
> x$a: lev1
>   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
>  1.444   1.596   2.295   2.232   2.295   3.529
> ------------------------------------------------------------
> x$a: lev2
>   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
> -1.6490 -1.1160 -0.4043 -0.3330 -0.2023  1.7060
>
> ...but I need them saved as a CSV file, so I'd like the result to have the form of:
>
> level    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
>  lev1   1.444   1.596   2.295   2.232   2.295   3.529
>  lev2  -1.6490 -1.1160 -0.4043 -0.3330 -0.2023  1.7060
>
> Can you give me any hints?
>
> Regards,
> Maciej
>
> --
> Maciej Blizi??ski <m.blizinski at wit.edu.pl>
> http://automaciej.blogspot.com/
>
> ______________________________________________
> 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
>