1 Goal


The goal of this tutorial is to learn how to assign values to variables


2 Assign a numerical value to a variable


# We can assign a numerical value to a variable with
a <- 5

# And print the result
a
## [1] 5
# The assignment also works in the other direction but we recommend to keep the left to right logic
6 -> a

#print
a
## [1] 6
# We can create a second variable and add it to the first one
b <- 10

#print a + b
a + b
## [1] 16
# Now we can store this value inside a third variable
c <- a + b
c
## [1] 16
# In R it is possible to use the = for assignment but it is not adviced 
c = 10
c
## [1] 10
# Use the spaces in your own advantage as
b <- 3

# Is different from
b < -3
## [1] FALSE

3 Assign character values to variable


# We use quatation marks to declare character variables
a <- "Hello World"
a
## [1] "Hello World"
# To create new characters from character variables check the paste tutorial
paste("Happy",c("birthday", "new year", "holidays"))
## [1] "Happy birthday" "Happy new year" "Happy holidays"

4 Conclusion


In this tutorial we have learnt how to assign values to variables using <-.