Re: [R] Not sure how to use aggregate, colSums, by

2011-08-14 Thread Dennis Murphy
Hi: Here's another approach using the reshape2 package. I called your data frame dat in the code below. library('reshape2') mdat <- melt(dat, measure = c('y', 'f')) acast(mdat, e1 ~ variable ~ e2, fun = sum, margins = 'e1') , , con y f can21 108 france 21 114 italy 21 126 usa

Re: [R] Not sure how to use aggregate, colSums, by

2011-08-14 Thread Jorge Ivan Velez
Hi eric, Try lapply(with(x, split(x, e2)), function(l){ r <- with(l, aggregate(list(y, f), list(e1), sum)) colnames(r) <- c('e1', 'y', 'f') r }) HTH, Jorge On Sun, Aug 14, 2011 at 1:20 PM, eric <> wrote: > I have a data frame called test shown below that i would like to summarize > in > a

Re: [R] Not sure how to use aggregate, colSums, by

2011-08-14 Thread Mikhail Titov
I hope this will help you get going b <- sapply(unique(test$e2), function(x) { out <- aggregate(cbind(y,f)~e1, subset(test, e2==x),"sum") out <- rbind(out, data.frame(e1="total", y=sum(out$y), f=sum(out$f))) out <- list(out) names(out) <- x out }) > b $std e1 y f 1

[R] Not sure how to use aggregate, colSums, by

2011-08-14 Thread eric
I have a data frame called test shown below that i would like to summarize in a particular way : I want to show the column sums (columns y ,f) grouped by country (column e1). However, I'm looking for the data to be split according to column e2. In other words, two tables of sum by country. One tab