Page 187 - Data Science Algorithms in a Week
P. 187
R Reference
Comments
Comments are not executed in R, start with the character # and end with the end of the line.
Input:
source_code/appendix_b_r/example01_comments.r
print("This text is printed because the print statement is executed")
#This is just a comment and will not be executed.
#print("Even commented statements are not executed.")
print("But the comment finished with the end of the line.")
print("So the 4th and 5th line of the code are executed again.")
Output:
$ Rscript example01_comments.r
[1] "This text will be printed because the print statemnt is executed"
[1] "But the comment finished with the end of the line."
[1] "So the 4th and 5th line of the code are executed again."
Data types
Some of the data types available in R are:
Numeric data types: integer, numeric
Text data types: string
Composite data types: vector, list, data frame
Integer
The integer data type can hold only integer values:
Input:
source_code/appendix_b_r/example02_int.r
#Integer constants are suffixed with L.
rectangle_side_a = 10L
rectangle_side_b = 5L
rectangle_area = rectangle_side_a * rectangle_side_b
rectangle_perimeter = 2*(rectangle_side_a + rectangle_side_b)
#The command cat like print can also be used to print the output
#to the command line.
cat("Let there be a rectangle with the sides of lengths:",
[ 175 ]