This works. But I wish I could write it without a lot of trial and error. :-(
ha = matrix(nrow=7, ncol=24) colnames(ha) = as.character(c(0:23)) rownames(ha) = rownames(maxrdf) m = as.matrix(maxrdf) for(j in 1:7) { x = aggregate(m[j,], by=list(s), FUN=sum) ha[j,] = x[[2]] } On 2/7/2010 1:57 PM, James Rome wrote: 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 ______________________________________________ R-help@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.