Re: [R] Sum by column

2011-01-12 Thread Felipe Carrillo
US Fish & Wildlife Service California, USA http://www.fws.gov/redbluff/rbdd_jsmp.aspx - Original Message ---- > From: Peter Francis > To: r-help@r-project.org > Sent: Wed, January 12, 2011 2:38:19 AM > Subject: [R] Sum by column > > Dear List, > > I have a ques

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

[R] Sum by column

2011-01-12 Thread Peter Francis
Dear List, I have a question of convenience, I am looking to sum the values of one column based on another column - a example may help explain better! ED ECOCODE 21.809467 AA0101 36.229566 PA1201 51.861284 PA1201 11.36232PA1201 27.264634 PA12