Vectors in R

Interactive R tutorial on vectors: create them with c(), index elements, run vectorized maths, and use seq() and rep() β€” all live in your browser.

A vector is a sequence of values β€” the fundamental building block of R. Edit and Run each box.

Create a vector with c()

c() (for β€œcombine”) glues values into a vector:

Vectors can hold text too:

Maths happens on every element at once

This is R’s superpower β€” no loops needed:

Pick out elements with [ ]

Square brackets select by position (R counts from 1):

That last line β€” selecting by a condition β€” is used constantly in real analysis.

Handy ways to build vectors

Summarise a vector

Your turn


Next: Data frames β†’ β€” organising vectors into a table.