[R] Aggregating the matrices
Sergey Goriatchev
sergeyg at gmail.com
Mon Sep 6 15:56:28 CEST 2010
Hello everyone.
Say we have the following:
a <- matrix(c(-75, 3, 5, 9, 2, 3, 5), nrow=1, dim=list("06092010",
c("ES", "PT", "Z ", "CF", "GX", "ST", "EO")))
b <- matrix(c(-5, 2, 4, 12, 5), nrow=1, dim=list("06092010", c("PT",
"CF", "AT", "EM", "ST")))
d <- cbind(a, b)
I want to calculate sums of the columns that have similar column names
and then output this summary
What I want to have is an array that looks like:
ES PT Z CF...
-75 -2 5 11...
I tried the following, but it did not work:
aggregate(d, list(colnames(d)), sum)
How can I achieve my objective?
Thank you in advance.
Sergey
More information about the R-help
mailing list