Re: [R] Zero counts in an aggregate function

From: noellejm <noellejm_at_u.washington.edu>
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))

    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.

______________________________________________
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 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 https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive