[R] Transforming results of the summary function

From: Maciej Bliziński <m.blizinski_at_wit.edu.pl>
Date: Fri 17 Feb 2006 - 19:06:21 EST


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@wit.edu.pl>
http://automaciej.blogspot.com/

______________________________________________
R-help@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
Received on Fri Feb 17 19:10:18 2006

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:42:33 EST