📌  相关文章
📜  在 R 编程中检查向量对象的存在 - is.vector()函数

📅  最后修改于: 2022-05-13 01:55:27.853000             🧑  作者: Mango

在 R 编程中检查向量对象的存在 - is.vector()函数

R 语言中的is.vector()函数用于返回 TRUE,如果给定的向量是指定的模式,除了名称之外没有其他属性。否则返回 FALSE。

示例 1:

# R program to illustrate
# is.vector function
  
# Initializing some data types
x <- c(a = 1, b = 2)
y <- list(c("GFG", "gfg"), matrix(c(1, 2, 3)))
z <- "Geeks"
  
# Calling is.vector() function
is.vector(x)
is.vector(y)
is.vector(z)

输出:

[1] TRUE
[1] TRUE
[1] TRUE

示例 2:

# R program to illustrate
# is.vector function
  
# Initializing some data types
x <- c(a = 1, b = 2)
y <- list(c("GFG", "gfg"), matrix(c(1, 2, 3)))
z <- "Geeks"
  
# Calling is.vector() function
is.vector(x,  mode = "list")
is.vector(x,  mode = "expression")
is.vector(x,  mode = "any")
is.vector(y,  mode = "list")
is.vector(y,  mode = "expression")
is.vector(y,  mode = "any")
is.vector(z,  mode = "list")
is.vector(z,  mode = "expression")
is.vector(z,  mode = "any")

输出:

[1] FALSE
[1] FALSE
[1] TRUE
[1] TRUE
[1] FALSE
[1] TRUE
[1] FALSE
[1] FALSE
[1] TRUE