R is a programming language used for statistical analysis, graphical presentation, and reporting. It also helps with data cleaning, analysis, and visualization.
In R, we type the number without a quote to return a number as an output.
# to print 5 5 # to print 2.5 2.5 # to print -20 -20 # to print some other numbers 10 -1.5
In R, we use single or double quotes to return a text as an output.
'Hello World' "Hello World"
To perform calculations in R, we type the numbers together with the mathematical operator sign.
# Addition 10 + 5 # Subtraction 10 - 5 # Multiplication 10 * 5 # Division 10 / 5 # Modulo 10 %% 5 # Exponentiation 10 ^ 5
R does not require the print
function to return an output of a code. It has the print()
function if we wish to use it. We use the print()
function only when we’re working with for
loops.
"Hello world" 'Hello World' print('Hello World') # using a for loop for (x in 1:5) { print(x) }
Note: Using the
print()
function is only compulsory withfor
loop. This is because the code is inside curly braces{}
.
RELATED TAGS
CONTRIBUTOR
View all Courses