OneBite.Dev - Coding blog in a bite size

convert variable from float to int in R

Code snippet on how to convert variable from float to int in R

floating_variable <- 5.6
integer_variable <- as.integer(floating_variable)

This code snippet assigns a floating number, 5.6, to a variable named “floating_variable”. Then, the as.integer() function is used to convert the floating number to an integer and assign it to a new variable, named “integer_variable”. The result of this code will be that the integer_variable will contain the value 6.

r