Description Usage Arguments Details Value Author(s) See Also Examples
When numbers should be integers but aren't because of floating point arithmetic issues.
1 | asInteger(x)
|
x |
object to be coerced. |
Standard coercion to integer using as.integer
truncates floats.
That behaviour can produce unexpected results when the number is used for subsetting or in a comparaison.
An integer vector.
Antoine Filipovic Pierucci
1 2 3 4 5 6 7 | (z <- .3 / .1) == 3 # FALSE
as.integer(z) == 3 #FALSE
asInteger(z) == 3 # TRUE
x <- letters[1:5]
x[z] # not "c"
x[asInteger(z)] # "c"
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.