Re: [R] aggregate and stack

From: Stephen D. Weigand <>
Date: Thu 26 May 2005 - 12:44:56 EST

Dear Paulo,

On May 25, 2005, at 8:01 PM, Paulo Brando wrote:

> Dear All,
> I have tried to calculate tree mean growth but I think the structure I
> used below (growthresumo) is not the most elegant, even though it
> worked. The only problem I had in this first part was that I cannot
> use 'summary', just 'mean' (sorry but 'R' is pretty new for me).

In case you didn't notice, help(aggregate) indicates that 'FUN' should be a scalar function, so summary won't work for that reason.

>> growthresumo <-
>> aggregate(growth[,c(16,19,23,27,31,35,39,43,47,52,56,60,64,68,72,76,81
>> ,85,89,93,97,101,105,109,113,117,121,125,129,133,137,
> 141,145,149,153,157,161,165,169,173,177,181,185,189,194,197,201,205,209
> ,213,217,221,225,229,233,237,241)],
> by=(growth[,c(3,8)]),MEAN,na.rm=TRUE)

It's hard to know where 'growth' came from. Is it your own data.frame, or from a package? It's better to provide a reproducible or toy example (as you'll often read here).

> #after growth is calculated, I want to stack the results in just one
> colunm.
>> growthvertical <- c(growthresumo[,3],...,growthresumo[,50]) # this is
>> very time consuming though

This comes to my mind:


but look up the help on stack() because it's a very powerful tool that is aptly named (and might do everything you want).

>> Parcel <- c("C9","S8"..."C9","S8") # 50 items

rep() could help with the above.

>> date < c("DATE1"...."DATE50")

paste() will help with this.

>> growthpermonth <- data.frame(Parcel, Date, growthvertical)
> Thank you very much!

Good luck with R!

Stephen mailing list PLEASE do read the posting guide! Received on Thu May 26 12:50:33 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:06 EST