[R] tapply, data.frame problem

From: Lauri Nikkinen <lauri.nikkinen_at_iki.fi>
Date: Wed 17 Jan 2007 - 19:43:56 GMT


Hi R-users,

I'm quite new to R and trying to learn the basics. I have a following problem concerning the convertion of array object into data frame. I have made following data sets

tmp1 <- rnorm(100)
tmp2 <- gl(10,2,length=100)
tmp3 <- as.data.frame(cbind(tmp1,tmp2))

tmp3.sum <- tapply(tmp3$tmp1,tmp3$tmp2,sum)
tmp3.sum <- as.data.frame(tapply(tmp1,tmp2,sum)) and I want the levels from tmp2 be shown as a column in the data.frame, not as row name as it now does. To put it in another way, as a result, I want a data frame with two columns: levels and the sums of those levels. Row names can be, for example, numbers from 1 to 10.

-Lauri Nikkinen
Lahti, Finland

        [[alternative HTML version deleted]]



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 and provide commented, minimal, self-contained, reproducible code. Received on Thu Jan 18 06:49:12 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 17 Jan 2007 - 20:30:30 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.