TabulateInt: Allows Tabulate to Be Used with Negative Integers Too

Description Usage Arguments Value Note Author(s) Examples

View source: R/TabulateInt.R

Description

Modifies tabulate to work with non-positive integers too.

Usage

1

Arguments

vec

The input vector

Value

A named integer vector. There is a bin for each of the values 1, ..., nbins.

Note

The behavior on non-integers might be somewhat unpredictable, but should be somewhat like using table(cut(...)) with breaks being from the minimum to the maximum + 1. See the "Examples" section.

Author(s)

Ananda Mahto

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
x <- c(-5, -5, 3, 1, 0, 2, 5, -4, 0, 0, 1)
TabulateInt(x)

## Compare
tabulate(x)
table(x)
table(factor(x, min(x):max(x)))

## Non-integers
set.seed(1)
x <- rnorm(20)
TabulateInt(x)
table(cut(x, seq(min(x), max(x)+1, 1), include.lowest = TRUE))

mrdwab/SOfun documentation built on June 20, 2020, 6:15 p.m.