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

Using variables

This lesson covers the basics of using variables in R, with the aim of understanding the assignment operator.

A variable is like a labelled box that stores a value under a name. The traditional way to assign in R is <- (though = also works). paste0() joins strings together.

The sample code declares two variables, name <- "Alice" and age <- 14, and assembles a greeting with cat(paste0(...)). The arrow-shaped <-, which points in the direction of the assignment, is a notation peculiar to R.

A common early stumble is how to join strings. R uses the paste0 or paste functions rather than +, which catches out anyone arriving from another language.

In professional work, the fact that R treats even a single value as a vector of length one means "every variable is a vector" — a way of thinking that matters later on for aggregation.

๐Ÿ“– 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)