检查对象是否是 R 编程中的列表 - is.list()函数
R语言中的is.list()
函数用于如果指定的数据是列表形式,则返回TRUE,否则返回FALSE。
Syntax: is.list(X)
Parameters:
x: different types of data storage
示例 1:
# R program to illustrate
# is.list function
# Initializing some list
a <- list(1, 2, 3)
b <- list(c("Jan", "Feb", "Mar"))
c <- list(matrix(c(1, 2, 3, 4, 5)))
d <- list(list("green", 12.3))
# Calling is.list() function
is.list(a)
is.list(b)
is.list(c)
is.list(d)
输出:
[1] TRUE
[1] TRUE
[1] TRUE
[1] TRUE
示例 2:
# R program to illustrate
# is.list function
# Initializing a data frame "Biochemical Oxygen
# Data" data sets
x <- BOD
# Each row of the data frame is a list
a <- x[2, ]
# Each column of the data frame is not a list
b <- x[, 1]
# Calling is.list() function
is.list(a)
is.list(b)
输出:
[1] TRUE
[1] FALSE