Name: Achmad Fahry Baihaki
NIM: 2206065110100
Institute: Maulana Malik Ibrahim Islamic State University of Malang
Departement: Computer Science
Lecturer: Prof. Dr. Suhartono, M.Kom


Initialize is a technique to assigning values to variables.

Variables is a place to store the values.

There are three ways to initialize the variables in R programming language. We can use:

  1. ” <- “,

  2. ” -> ” or

  3. ” = ”

In this article we will learn to initialize variables using three of it and operate the variables.

1. Initialize using ” <- ”
carPrice <- 5000
2. Initialize using ” -> ”
8000 -> carPrice
3. Initialize using ” = ”
shoesPrice = 10000

If we can see the values of the variables, we need to call the variables/object directly or also we can use the ” print() ” syntax.

Here’s the examples:

1. Call directly
carPrice
## [1] 8000
2. Call using print() method.
print(shoesPrice)
## [1] 10000

After that, we can use mathematical operations to operate the variables.

Here’s the example:

The story, in this case we want to calculate the area of a square.

squareSide <- 9
squareArea = squareSide * squareSide

print(squareArea)
## [1] 81

Tips

we can check what variables have been created and we can also delete them.

To check the set of the variables, use “ls()” command. Here’s the example:

ls()
## [1] "carPrice"   "shoesPrice" "squareArea" "squareSide"

And if we want to delete the variables, we can use “rm()” command. Example:

Delete the carPrice variables.

rm(carPrice)