Lets introduce a concept that is fundamental to R. Objects and object assignment.

An object is anything in R that holds information for R to use. We assign information to an object using the arrow <- or the single equal sign =

x <- 2 # a simple object, x, containing the data 2
x #if we type x, then the information within x will be printed
## [1] 2

When we assign data to an object in R, we use the Arrow symbol <-. Think of it as the information you are wanting to retain is flowing into the object via the arrow sign.

Objects can be named any combination of characters and numerical information

What makes an object useful, is that we can apply functions to the data contained within.

#Watch that in all of the below examples, x is equal to 10
x<- 10 #x is equal to 10
x+2
x*6
x/2
## [1] 12
## [1] 60
## [1] 5

Objects can contain more than a single number of course. The object below contains many numbers and we can run functions that apply to all of the values contained within the object.

x <- c(2,4,5,6,7,8,2)  #Now x contains all the numbers 2,4,5,6,7,8,2
x+10 #We can add 10 to every number
x*2 #we can multiply all the numbers by 2
sum(x) #we can get the sum of all those values
mean(x) #we can get the mean of all these values
## [1] 12 14 15 16 17 18 12
## [1]  4  8 10 12 14 16  4
## [1] 34
## [1] 4.857143

Objects are a core component of R programming. But objects don’t just need to be simple numbers. Lets explore the different classes of objects we can use in R.

Last modified: Tuesday, 2 December 2025, 4:41 AM