countDistinct {rrMisc}R Documentation

SQL-command 'count(distinct ...)' convreted to R

Description

SQL-command 'count(distinct ...)' convreted to R

Usage

countDistinct(x, ...)

Arguments

x

Vector or data.frame in which the number of different entries are counted.

...

arguments passed to further functions

Details

Returns the number of distinct values and indicates if there are NAs present

Value

named vector of numbers

- count: number of different entries (without NAs)

- NAs: index of NAs present (0=no, 1=yes)

Note

under continuous developement

Author(s)

Roland Rapold

References

none

Examples

print("Example for vector")
                      c(pi, NA, 4.000000, 5.000000, 5, 6, 5, 6)
               length(c(pi, NA, 4.000000, 5.000000, 5, 6, 5, 6))
        countDistinct(c(pi, NA, 4.000000, 5.000000, 5, 6, 5, 6))
       length(na.omit(c(pi, NA, 4.000000, 5.000000, 5, 6, 5, 6)))
countDistinct(na.omit(c(pi, NA, 4.000000, 5.000000, 5, 6, 5, 6)))
#
if(require("MASS"))
{
    print("Example for data.frame")
    data(crabs, package="MASS")
    str(crabs)
    print(countDistinct(crabs[, c("sp")]))
    print(countDistinct(crabs[, c("sex")]))
    print(countDistinct(crabs[, c("FL")]))
}

[Package rrMisc version 0.33 Index]