Description Usage Arguments Details Value Note Author(s) References Examples
SQL-command 'count(distinct ...)' convreted to R
1 | 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
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")]))
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.