[R] how to count number of elements in a vector that are not NA ?

Godmar Back godmar at gmail.com
Tue Jul 7 20:56:54 CEST 2009


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




More information about the R-help mailing list