Open In App
Related Articles

Check for the Existence of a Vector Object in R Programming – is.vector() Function

Improve Article
Improve
Save Article
Save
Like Article
Like

is.vector() function in R Language is used to return TRUE if the given vector is of the specified mode having no attributes other than names. It returns FALSE otherwise.

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

Parameters:
x: R object
mode: character string naming an atomic mode or “list” or “expression” or “any”

Example 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)


Output:

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

Example 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")


Output:

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

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 19 Jun, 2020
Like Article
Save Article
Previous
Next
Similar Reads