Learn R Programming

BBmisc (version 1.10)

convertIntegers: Conversion for integer vector.

Description

Convert numeric vector to integer vector if the numeric vector fully represents an integer vector, e.g. c(1, 5) to c(1L, 5L). Otherwise the argument is returned unchanged.

Usage

convertIntegers(x)

Arguments

x
[any] Argument.

Value

Either an integer vector if conversion was done or x unchanged.

Examples

Run this code
str(convertIntegers(1.0))
str(convertIntegers(1.3))
str(convertIntegers(c(1.0, 2.0)))
str(convertIntegers("foo"))

Run the code above in your browser using DataLab