- Learning Shiny
- Hernán G. Resnizky
- 204字
- 2021-07-09 21:46:10
Variables in R
Unlike Java or C#, R enables total flexibility in the assignment of variables. This means that you can assign objects of different types to the same variable. This will cause overriding:
var1 <- 10 var1 <- "a string"
In this case, for instance, R will not throw an error for var1
. In addition, there is no need to pre-declare the class of the variable.
The assignment of variables in R can be done in the following three ways:
For conventional variable assignments, there is no need to use this function. However, it becomes particularly useful if dynamic naming of a variable is needed (a function could eventually be used to determine the name of a variable in the first argument of the function) or, if needed, a variable can be assigned to another environment (this issue will not be covered in this book, for further information about this, visit http://adv-r.had.co.nz/Environments.html).
R is case sensitive. This means that upper and lower case are relevant. For instance, the var1
and Var1
variables are semantically two completely different objects.