Variables can be assigned using any of the leftward, rightward or equal to operator. You can print the variables using either print or cat functions.
How to declare variables
var-name = value
var-name <- value
value -> var-name
Naming convention of variables
- Variable names can have only letters (both uppercase and lowercase letters), numbers, dot and underscore(
_). - Variables naming cannot contain white spaces like
first namewhich is a invalid variable name. - First letter of a variable should be either a letter or dot (
.). - In R, Variable names are case sensitive and hence Name and name both are different.
- It is always advisable to give some meaningful names to variables.
Example
var_logical <- FALSE # Logical variable
var_numeric -> 797 # Numeric variable
var_integer = 53L # integer variable
var_complex <- 5+2i # complex variable
var_char<- "One Compiler" # character variable
var_raw <- charToRaw("Hello World") # raw variable