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

______________________________________________
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.

Reply via email to