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

Description Usage Arguments Details Value Note Author(s) References Examples

View source: R/compare.R

Description

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

Usage

1

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
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")]))
}

rrMisc documentation built on June 25, 2021, 3 a.m.