在 R 编程中检查一个值是否是逻辑的 - is.logical()函数
R 语言中的is.logical()
函数用于检查值是否符合逻辑。
Syntax: is.logical(x)
Parameters:
x: Value to be checked
示例 1:
# R Program to test whether
# a value is logical or not
# Calling is.logical() function
is.logical(0)
is.logical(!5)
is.logical(T)
is.logical(FALSE)
输出:
[1] FALSE
[1] TRUE
[1] TRUE
[1] TRUE
示例 2:
# R Program to test whether
# a value is logical or not
# Creating vector
x1 <- c(1, 2, 3, 4)
x2 <- c(T, F, TRUE, FALSE, ! 2)
x3 <- c(1, T, F)
# Calling is.logical() function
is.logical(x1)
is.logical(x2)
is.logical(x3)
输出:
[1] FALSE
[1] TRUE
[1] FALSE