← Back to R Course | Chapter 3: Vectors | Lesson 1 of 7

Creating Vectors

In this page:

  1. Creating Vectors

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

markup
x <- 5
y <- c(1, 2, 3, 4, 5)

cat(length(x), length(y), "\n")
print(y)
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.