# 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
Run the code above in your browser using DataLab