[R] by or tapply?

From: Michael Denslow <mwdenslow_at_yahoo.com>
Date: Thu, 03 Jul 2008 20:54:08 -0700 (PDT)


Dear R-helpers,

I have a data frame that is similar to the one below. The row names are species and the E1, E2, E3 columns are presence/absence for a given site. I have an additional column 'origin' which has information about the species.

     E1 E2 E3 origin
BASA  0  0  1      N
BASO  0  0  1      N
BRCO  0  0  1      U
CAER  0  0  0      E
CAGI  0  1  0      C
CEFL  0  1  1      N

I want to get the sum of ALL of the sites for the factors in the column 'origin'.

I have used

by(merge[,2],merge$origin,sum)
and
tapply(merge[,2],merge$origin,sum)

but this just gives me one column at a time. How can I get all of the sites summed individually and end up with the site names as rows and the factors be the columns.

Thanks in advance for your help!
Michael



R-help_at_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. Received on Fri 04 Jul 2008 - 03:59:39 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 04 Jul 2008 - 07:31:23 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive