Re: [R] Sum by column

2011-01-12 Thread Felipe Carrillo
Or with ddply : library(plyr) dat <- structure(list(ED = c(21.809467, 36.229566, 51.861284, 11.36232, 27.264634, 12.261986, 46.519313, 7.815376, 2.810428, 13.478372, 35.670182, 27.128715, 19.010294, 15.475368, 18.597983, 29.292615, 6.749846, 14.981488, 14.93511, 14.93511, 21.040785, 8.271615, 12.94

Re: [R] Sum by column

2011-01-12 Thread Peter Francis
David and Josh, Thanks very much for your help, it is much appreciated. Peter On 12 Jan 2011, at 14:28, David Winsemius wrote: There are two functions you need to become familiar with: ?tapply ?ave If you wanted these summed values to be placed in another column of the same dataframe, you w

Re: [R] Sum by column

2011-01-12 Thread Joshua Wiley
Hi Peter, R has some fairly flexible ways of passing values of some variable (X) by another (the INDEX) to different FUNctions. Here is an example using your data: ## your email data, in convenient form dat <- structure(list(ED = c(21.809467, 36.229566, 51.861284, 11.36232, 27.264634, 12.261986,

Re: [R] Sum by column

2011-01-12 Thread David Winsemius
There are two functions you need to become familiar with: ?tapply ?ave If you wanted these summed values to be placed in another column of the same dataframe, you would use ave. If you wanted a new structure (somewhat shorter) you would use tapply with sum as the function. E. g: tapply(eco