The as.integer() function in R transforms a character object into an integer object.
as.integer(x)
The as.integer() function takes a single mandatory parameter, x, representing the character object passed.
The as.integer() function returns an integer object.
# calling the as.integer() function on character objectsas.integer("1")as.integer("1.5")as.integer("10")as.integer("-10.5")as.integer("0x290")
We call the as.integer() function on some given character objects in the code above. The function helps return their values as integer objects.
# creating a vectormyvector <- c(1, 2, 3, 4, 5)# converting the vector to integermyinteger <- as.integer(myvector)myinteger# to check if it is an integeris.integer(myinteger)
myvector.as.integer() function on the vector object myvector. We assign the result to another variable, myinteger.myinteger.myinteger is an integer object, we make use of the is.integer() function.