实例 R 语言 从一种类型转换为另一种类型

x
 
x <- 1L # integer
y <- 2  # numeric
# convert from integer to numeric:
a <- as.numeric(x)
# convert from numeric to integer:
b <- as.integer(y)
# print values of x and y
x
y
# print the class name of a and b
class(a)
class(b)
                    

输出结果

[1] 1
[1] 2
[1] "numeric"
[1] "integer"