Using Variables in R
In R programming, we will be using variables all the time, so it is important to understand what a variable is and how it works in R.
A variable refers to a named storage that allows us to store data which our R programs can refer to and manipulate. A variable in R can store a value or an object (more on objects later). For example, we can store value ’50’ in a variable called ‘x’. This is called variable assignment, that is, the variable ‘x’ is assigned value ’50’.
The variables can be assigned values using leftward, rightward and equal to operator, however, the most common way is to use the leftward operator ( <- )
Once we have assigned a value to a variable, we can print it by just calling the variable name or by using the print() or the cat() function.
1# Assignment using equal operator.
2x = 50
3
x

