Creating Variables in R Language
Let’s look at ways of declaring and initializing variables in R language:
R supports three ways of variable assignment:
- Using equal operator- operators use an arrow or an equal sign to assign values to variables.
- Using the leftward operator- data is copied from right to left.
- Using the rightward operator- data is copied from left to right.
Syntax for creating R Variables
Types of Variable Creation in R:
- Using equal to operators
variable_name = value
- using leftward operator
variable_name <- value
- using rightward operator
value -> variable_name
Creating Variables in R With Example
Let’s look at the live example of creating Variables in R:
R
# R program to illustrate # Initialization of variables # using equal to operator var1 = "hello" print (var1) # using leftward operator var2 <- "hello" print (var2) # using rightward operator "hello" -> var3 print (var3) |
[1] "hello" [1] "hello" [1] "hello"
R Variables – Creating, Naming and Using Variables in R
A variable is a memory allocated for the storage of specific data and the name associated with the variable is used to work around this reserved block.
The name given to a variable is known as its variable name. Usually a single variable stores only the data belonging to a certain data type.
The name is so given to them because when the program executes there is subject to change hence it varies from time to time.