NPHIL Lec 2 R
NPHIL Lec 2 R
Data Types in R
We can use the class() function to check the data type of a variable:
Basic syntax in R
Keywords in R
These words are: function, if, else, for, while, repeat, break, next, TRUE, FALSE, inf,
NAN, NA_real, NA_Integer, NA_Complex, NA_character, NULL
Variables
Variable is the storage of our program, or a variable is used to store data
Assiigning value to a variable
Method 1
We use the leftward operator, <- ( the less than sign follow by a hypen)
Code: var_name <- value
Method 2
We use the assignment operator , = ( the equal to sign)
Code: var_name = value
Method 3
We use the rightward operator, >- The greater than sign follow by a hypen)
Code: var_name >- value
To see the list of variables we use in our program , we use the ls() function
Code: ls()
To remove a variable from the list of variables, we use the remove function.
Comment
Comments are use to keep track of the code you have written. It is for the user only,
so the interpreter ignore it
The # (hash) symbol is use to comment a code, it is usually written above the code.