检查对象是否是 R 编程中的字符类型 - 是。字符()函数
R 语言中的is.character()
函数用于检查作为参数传递给它的对象是否为字符类型。
Syntax: is.character(x)
Parameters:
x: Object to be checked
示例 1:
# R program to check if
# object is a character
# Creating a vector
x1 <- 4
x2 <- c("a", "b", "c", "d")
x3 <- c(1, 2, "a", 3, "b")
# Calling is.character() function
is.character(x1)
is.character(x2)
is.character(x3)
输出:
[1] FALSE
[1] TRUE
[1] TRUE
示例 2:
# R program to check if
# object is a character
# Creating a matrix
x1 <- matrix(letters[1:9], 3, 3)
# Calling is.character() function
is.character(x1)
输出:
[1] TRUE