countDistinct {rrMisc} | R Documentation |
SQL-command 'count(distinct ...)' convreted to R
countDistinct(x, ...)
x |
Vector or data.frame in which the number of different entries are counted. |
... |
arguments passed to further functions |
Returns the number of distinct values and indicates if there are NAs present
named vector of numbers
- count: number of different entries (without NAs)
- NAs: index of NAs present (0=no, 1=yes)
under continuous developement
Roland Rapold
none
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")])) }