Check if values are integers and convert to integer | R Documentation |
Check if values are integers and convert to integer.
is_integer(x)
as_integer(x,result.sort = TRUE,init = 1)
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. |
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.
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".
R implementation and documentation: Manos Papadakis <papadakm95@gmail.com>.
as_integer, colVars, colmeans, read.directory
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.