在 R 编程中获取或设置对象的类型 - mode()函数
R语言中的mode()
函数用于获取或设置对象的类型或存储模式。
Syntax:
mode(x)
mode(x) <- value
Here "value" is the desired mode or ‘storage mode’ (type) of the object
Parameters:
x: R object
示例 1:
# R program to illustrate
# mode function
# Initializing some values
x <- 3
y <- "a"
# Calling the mode() function
mode(x)
mode(y)
输出:
[1] "numeric"
[1] "character"
示例 2:
# R program to illustrate
# mode function
# Initializing some values
x <- 3
y <- "a"
# Calling mode() function to
# set the storage mode of the object
mode(x) <- "character"
mode(y) <- "numeric"
# Getting the assigned storage mode
mode(x)
mode(y)
输出:
[1] "character"
[1] "numeric"