Creating Vectors
In this page:
Creating Vectors
A vector is R's most fundamental data structure -- an ordered collection of values that all share the same type. Even a single value like x <- 5 is technically a vector of length 1. Vectors are the building block that most of R's other data structures, like matrices and data frames, are built from.
Note: Almost everything in R is a vector, even scalars -- there is no separate single-value type.
Example: Creating Vectors
x <- 5
y <- c(1, 2, 3, 4, 5)
cat(length(x), length(y), "\n")
print(y)
Login to try C/C++/Java/PHP code in the editor
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: