[R] how to count number of elements in a vector that are not NA ?
Giovanni Petris
GPetris at uark.edu
Tue Jul 7 23:30:20 CEST 2009
sum(!is.na(x))
> Date: Tue, 07 Jul 2009 14:56:54 -0400
> From: Godmar Back <godmar at gmail.com>
> Sender: r-help-bounces at r-project.org
> Precedence: list
> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;
> DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma;
>
> Hi,
>
> is there a simpler way to count the number of elements in a vector
> that are not NA than this:
>
> countN <- function (v) {
> return (Reduce(function (x, y) x + y, ifelse(is.na(v), 0, 1)))
> }
>
> ?
>
> - Godmar
>
> ______________________________________________
> 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.
>
>
More information about the R-help
mailing list