[R] getting data into correct format for summarizing ... reshape, aggregate, or...

Sebastian P. Luque spluque at gmail.com
Mon Sep 15 18:39:35 CEST 2008


On Mon, 15 Sep 2008 12:14:40 -0400,
"stephen sefick" <ssefick at gmail.com> wrote:

> I would like to reformat this data frame into something that I can
> produce some descriptive statistics.  I have been playing around with
> the reshape package and maybe this is not the best way to proceed.  I
> would like to use RiverMile and constituent as the grouping variables
> to get the summary statistics:

> 198a 198b mean mean sd sd ...  ...

> etc. for all of these.  I have tried reshape and aggregate and I am
> sure that I am missing something...

df <- data.frame(RiverMile=c(rep(215, 10), rep(202, 10), rep(198, 10)),
                 constituent=gl(2, 5, 30, labels=letters[1:2]),
                 value=rnorm(30))

by(df, list(df[[1]], df[[2]]), summary) # or build your summary function
---<---------------cut here---------------end---------------->---

?

-- 
Seb



More information about the R-help mailing list