Ad space (banner)
๐Ÿ“ŠR Lessons
Lesson 7 / 68

Working with vectors

This lesson covers the basics of using vectors in R, with the aim of handling several pieces of data together.

A vector is like a shelf of numbered drawers. The c() function creates one. It is the basic unit of data handling in R and its single most important data structure.

The sample code builds a vector with fruits <- c("apple", "orange", "grape") and displays each element with a number using for (i in 1:length(fruits)). Note that R vectors are indexed from 1.

A common early stumble is exactly that: indexes start at 1, not 0. Most other languages (Python, JavaScript) start at 0, so the difference trips people up on arriving at R.

In professional work, vectors are R's most basic tool, used to gather experimental or observational data for aggregation and analysis.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run R directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)