Skip to contents

Calculates the number of times each unique element occurs after excluding missing values. A fast, generalized alternative to base::tabulate().

Usage

ftabulate(x, is_sorted = FALSE)

Arguments

x

(Atomic vector)
The atomic vector for tabulation.

is_sorted

(Scalar logical: FALSE)
Whether or not x is already sorted. Only set is_sorted = TRUE when x is guaranteed to already be sorted.

Value

Integer vector

Details

base::tabulate() only counts positive integers. ftabulate() will count any nonmissing element type.

Examples

#----------------------------------------------------------------------------
# ftabulate() example
#----------------------------------------------------------------------------
library(bkbase)

x <- sample(1:10, size = 100, replace = TRUE)
ftabulate(x)
#>  [1] 17 10 13  9 10 12 12  5  7  5
tabulate(x)
#>  [1] 12 10 17  5  5 13 12  9  7 10
table(x)
#> x
#>  1  2  3  4  5  6  7  8  9 10 
#> 12 10 17  5  5 13 12  9  7 10