[R] Zero counts in an aggregate function
    noellejm 
    noellejm at u.washington.edu
       
    Tue May 17 09:34:48 CEST 2011
    
    
  
On Mon, May 16, 2011 at 11:56 PM, Jorge Ivan Velez  wrote:
    Hi Noelle,
    Try using 
    count2 <- function(x)  sum(x == 0)
    or, for all at once (untested),
    foo <- function(x) c( alive = sum(x == 1), dead = sum(x == 0))
    with(bugs, tapply(SURVIVE, FRUIT, foo))
    HTH,
    Jorge
Hi Jorge,
The first bit of code didn't seem to work, but the second one did!
tapply worked but I also inserted "foo" into the aggregate code and was also
able to add the "alive" and "dead" columns to my data.
Thanks very much for your help!
Noelle
- Hide quoted text -
--
View this message in context: http://r.789695.n4.nabble.com/Zero-counts-in-an-aggregate-function-tp3528084p3528299.html
Sent from the R help mailing list archive at Nabble.com.
    
    
More information about the R-help
mailing list