helpers: Little helpers

Description Usage Arguments Value Examples

Description

Little helper functions that are often useful.

Usage

1
2
3
4
5

Arguments

x

An R object, usually a vector.

...

Other arguments to pass to unique().

Value

distinct() just calls length(unique(x, ...)), and returns a length 1 numeric with the number of unique elements in x.

allNA() just calls all(is.na(x)), and returns TRUE if all elements of x are NA, FALSE otherwise.

integer_digits() is roughly the same as nchar(abs(trunc(x))), but much faster, and returns a length 1 numeric.

Examples

1
2
3
4
5
6
7
8
9
distinct(1:3)

distinct(c(1:3, NA, NA)) # NAs are lumped together

distinct(c(1:3, NA, NA), incomparables = NA_real_)

integer_digits(-1.5) # same as nchar(abs(trunc(-1.5)))

integer_digits(Inf) # nchar(abs(trunc(Inf))) returns 3

marberts/smart documentation built on March 9, 2021, 5:31 p.m.