as.integer()发挥作用R语言用于将字符对象转换为整数对象。
语法:as.integer(x)
参数:x:字符对象
范例1:
# R program to convert a character object
# to an integer object
# Calling as.integer() function
as.integer( "4" )
as.integer( "1.6" )
as.integer( "-3.2" )
as.integer( "0x400" )
输出如下:
[1] 4
[1] 1
[1] -3
[1] 1024
范例2:
# R program to convert a character object
# to an integer object
# Creating a vector
x < - c( 1 , 2 , 3 , 4 , 5 )
# Check if the vector is an integer
is .integer(x)
# Convert to integer
x1 < - as.integer(x)
x1
# Calling is.integer() function
is .integer(x1)
输出如下:
[1] FALSE
[1] 1 2 3 4 5
[1] TRUE