當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


R語言 is.vector()用法及代碼示例


is.vector() R 語言中的函數用於返回 TRUE,如果給定的向量是指定的模式,除了名稱之外沒有其他屬性。否則返回 FALSE。

用法: is.vector(x, mode = “any”)

參數:
x:R對象
mode:命名原子模式或 “list” 或 “expression” 或 “any” 的字符串

範例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



相關用法


注:本文由純淨天空篩選整理自Kanchan_Ray大神的英文原創作品 Check for the Existence of a Vector Object in R Programming – is.vector() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。