is_vect {ds4psy} | R Documentation |
Test for a vector (i.e., atomic vector or list).
Description
is_vect
tests if x
is a vector.
Usage
is_vect(x)
Arguments
x |
Vector(s) to test (required). |
Details
is_vect
does what the base R function is.vector
is not designed to do:
-
is_vect()
returns TRUE ifx
is an atomic vector or a list (irrespective of its attributes). -
is.vector()
returns TRUE ifx
is a vector of the specifiedmode
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.
See Also
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()
Examples
# 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