is_integer: Check if values are integers and convert to integer

View source: R/is.R

Check if values are integers and convert to integerR Documentation

Check if values are integers and convert to integer

Description

Check if values are integers and convert to integer.

Usage

is_integer(x)
as_integer(x,result.sort = TRUE,init = 1)

Arguments

x

is_integer: A vector with numeric data. as_integer: A vector with data.

result.sort

A logical value for sorting the result.

init

An integer value to start.

Details

The behavior of these functions are different than R's built in.

is_integer: check if all the values are integers in memory. If typeof is double, and the values are integers in range -2^31 : 2^31 then it is better to convert to integer vector for using less memory. Also you can decrease the time complexity.

as_integer: converts the discrete values to integers.

Value

is_integer: A logical value, TRUE if all values are integers and in range -2^31 : 2^31. Otherwise FALSE.

as_integer: By default the function will return the same result with "as.numeric" but the user can change the "init" value not start from 1 like R's. Also the result can be unsorted using "result.sort".

Author(s)

R implementation and documentation: Manos Papadakis <papadakm95@gmail.com>.

See Also

as_integer, colVars, colmeans, read.directory

Examples

x<-runif(10)
y1<-is_integer(x) # y1 is FALSE
x<-as.numeric(rpois(10,10)) # integers but typeof is double
y1<-is_integer(x) # y1 is TRUE so you can convert to integer vector.

as_integer(letters) ## as.numeric(letters) produce errors
x<-y1<-NULL

Rfast documentation built on Nov. 9, 2023, 5:06 p.m.