Re: [R] Yearly aggregates and matrices

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Wed, 27 Apr 2011 21:19:35 -0400

On Wed, Apr 27, 2011 at 2:03 PM, mathijsdevaan <mathijsdevaan_at_gmail.com> wrote:
> Hi,
>
> Is there an alternative to "z <- read.zoo(DF, split = 2, index = 3, FUN =
> identity)" and "r <- rollapply(z, 3,  sum.na, align = "right", partial =
> TRUE)"? I am trying to use the following script in which the split data (B)
> contains about 300000 unique cases and obviously I am getting an allocation
> error. Thanks!
>

You could test the speed of this to see if its faster:

library(reshape2)
library(zoo)
mm <- melt(DF, id = c("B", "C"))
aa <- acast(mm, C ~ B + variable, FUN = sum) sum.na <- function(x) if (any(!is.na(x))) sum(x, na.rm = TRUE) else NA r <- rollapply(aa, 3, sum.na, align = "right", partial = TRUE)

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

______________________________________________
R-help_at_r-project.org 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 28 Apr 2011 - 01:25:47 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 29 Apr 2011 - 01:40:33 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.

list of date sections of archive