检查对象是否属于 R 编程中的字符数据类型 - 是。字符()函数
R 语言中的is.character()
函数用于检查对象是否为字符串/字符的形式。如果对象的任何元素是字符数据类型,它将返回 true。
Syntax: is.character(Object)
Parameter:
Object: It could be an array, list, vector, etc.
示例 1:
# R Program to illustrate
# the use of is.character function
# Creating a vector of mixed datatype
x1 <- c("Hello", "Geeks", 100)
# Creating a vector of Numeric datatype
x2 <- c(10, 20, 30)
# Calling is.character() function
is.character(x1)
is.character(x2)
输出:
[1] TRUE
[1] FALSE
示例 2:
# R Program to illustrate
# the use of is.character function
# Create the vectors with different length
vector1 <- c(1, 2, 3)
vector2 <- c("GFG", "Geeks", "Hello")
# taking this vector as input
result <- array(c(vector1, vector2), dim = c(3, 3, 2))
# Calling is.character() function
is.character(result)
输出:
[1] TRUE