Re: [R] Zero counts in an aggregate function

From: noellejm <>
Date: Tue, 17 May 2011 00:34:48 -0700 (PDT)

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))


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!

- Hide quoted text -

View this message in context:
Sent from the R help mailing list archive at

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Tue 17 May 2011 - 09:15:43 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

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 Tue 17 May 2011 - 09:20:07 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive