asInteger: Convert numeric values to rounded integers

View source: R/misc.R

asIntegerR Documentation

Convert numeric values to rounded integers

Description

Essentially a wrapper around round, rather than truncate, which is what as.integer does. Internally, this is simply as.integer(floor(x + 0.5)).

Usage

asInteger(x)

Arguments

x

A numeric vector

Value

An integer vector of length x, rounded to zero decimal places prior to as.integer

Note

Values ending in .5 will be rounded up, whether positive or negative. This is different than round.

Examples

x <- seq(-2, 2, 0.25)
data.frame(dbl = x, int = asInteger(x))

PredictiveEcology/LandR documentation built on June 7, 2024, 4:16 p.m.