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:
” <- “,
” -> ” or
” = ”
In this article we will learn to initialize variables using three of it and operate the variables.
carPrice <- 5000
8000 -> carPrice
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:
carPrice
## [1] 8000
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)