[R] Transforming results of the summary function
Maciej Bliziński
m.blizinski at wit.edu.pl
Fri Feb 17 09:06:21 CET 2006
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/
More information about the R-help
mailing list