Learn R Programming

ds4psy (version 0.6.0)

is_vector: Test for a vector (i.e., atomic vector or list).

Description

is_vector tests if x is a vector.

Usage

is_vector(x)

Arguments

x

Vector(s) to test (required).

Details

is_vector does what the base R function is.vector is not designed to do:

  • is_vector() 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 documentations of is.atomic, is.list, and is.vector for details.

See Also

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: is_equal(), is_wholenumber(), num_as_char(), num_as_ordinal(), num_equal()

Examples

Run this code
# NOT RUN {
# 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_vector(v1)

is.vector(v2)  # FALSE
is.list(v2)
is_vector(v2)  # TRUE

is.vector(ls)
is.list(ls)
is_vector(ls)

# Data frames are also vectors: 
df <- as.data.frame(1:3)
is_vector(df)  # is TRUE

# }

Run the code above in your browser using DataLab