is_vect | R Documentation |
is_vect
tests if x
is a vector.
is_vect(x)
x |
Vector(s) to test (required). |
is_vect
does what the base R function is.vector
is not designed to do:
is_vect()
returns TRUE if x
is an atomic vector or a list (irrespective of its attributes).
is.vector()
returns TRUE if x
is a vector of the specified mode
having no attributes other than names, otherwise FALSE.
Internally, the function is a wrapper for is.atomic(x) | is.list(x)
.
Note that data frames are also vectors.
See the is_vector
function of the purrr package
and the base R functions
is.atomic
, is.list
, and is.vector
,
for details.
is_vect
function of the purrr package;
is.atomic
function of the R base package;
is.list
function of the R base package;
is.vector
function of the R base package.
Other utility functions:
base2dec()
,
base_digits
,
dec2base()
,
is_equal()
,
is_wholenumber()
,
num_as_char()
,
num_as_ordinal()
,
num_equal()
# Define 3 types of vectors:
v1 <- 1:3 # (a) atomic vector
names(v1) <- LETTERS[v1] # with names
v2 <- v1 # (b) copy vector
attr(v2, "my_attr") <- "foo" # add an attribute
ls <- list(1, 2, "C") # (c) list
# Compare:
is.vector(v1)
is.list(v1)
is_vect(v1)
is.vector(v2) # FALSE
is.list(v2)
is_vect(v2) # TRUE
is.vector(ls)
is.list(ls)
is_vect(ls)
# Data frames are also vectors:
df <- as.data.frame(1:3)
is_vect(df) # is TRUE
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.