[R] Moving column averaging
bps0002 at auburn.edu
Sat Dec 3 21:39:18 CET 2011
I don't know the answer, but would suppose not.
You could test this for yourself using:
> This solved my problem - Thanks a lot for your help! Please allow me one
> more question: Works zoo's rollapply on a plain matrix faster than on a
> zoo object? I am asking since I wanted to apply the provided averaging
> code to a larger matrix (2500 rows x 200 cols), which is quite time
> Thanks again!
> From: B77S [via R] <ml-node+s789695n4143909h3 at .nabble>
> To: Chega <chegaga@>
> Sent: Friday, December 2, 2011 6:16 AM
> Subject: Re: Moving column averaging
> Sorry for that, and thanks Gabor,
> I could have sworn that it wouldn't.
> Gabor Grothendieck wrote
>>On Thu, Dec 1, 2011 at 7:13 PM, B77S <[hidden email]> wrote:
>>> # need zoo to use rollapply()
>>> # your data (I called df)
>>> df <- structure(list(a = 1:2, b = 2:3, c = c(5L, 9L), d = c(9L, 6L),
>>> e = c(1L, 5L), f = c(4, 7)), .Names = c("a", "b", "c", "d",
>>> "e", "f"), class = "data.frame", row.names = c(NA, -2L))
>>> # transpose and make a zoo object
>>> df2 <- zoo(t(df))
>>> #rollapply to get means and transpose back
>>> means <- t(rollapply(df2, width=2, by=2, FUN=mean))
>>> # adding the combined column names you requested
>>> colnames(means) <- apply(matrix(names(df), nrow=2), 2, paste,
>>> collapse=", ")
>>Note that zoo's rollapply also works on plain matrices and vectors.
>>Statistics & Software Consulting
>>GKX Group, GKX Associates Inc.
>>email: ggrothendieck at gmail.com
>>[hidden email] mailing list
>>PLEASE do read the posting guide
>>and provide commented, minimal, self-contained, reproducible code.
> If you reply to this email, your message will be added to the discussion
> To unsubscribe from Moving column averaging, click here.
View this message in context: http://r.789695.n4.nabble.com/Moving-column-averaging-tp4130179p4154770.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help