[R] Why does aggregate fail?
James Rome
jamesrome at gmail.com
Sun Feb 7 19:57:37 CET 2010
On 2/7/2010 1:35 PM, David Winsemius wrote:But to answer your question:
> apply(d, 1, function(z) aggregate(z, by=list(s), FUN=sum) )
David,
That works, but I do not understand why I could not use aggregate
directly. And the answer comes out as a list, which thus far baffles me.
How do I get the answer as a matrix in my original code, which I
modified to use apply?
ha = matrix(nrow=7, ncol=24)
colnames(ha) = as.character(c(0:23))
rownames(ha) = rownames(maxrdf)
for(j in 1:7) {
x = apply(maxrdf[j,], 1, function(z) aggregate(z, by=list(s),
FUN=sum) )
ha[j,] = x[[1]][2]
}
Unfortunately, ha gets converted into a list, and then I can't use it
for my plots. And you can probably educate me on how to get what I am
aiming for (a matrix with the rows as the days, the columns as the
hours, and the content as the hourly sum of the 15-minute chunks)
without using the above for loop.
Thanks for the help,
Jim
More information about the R-help
mailing list