This post is about performing arithmetic operations in R programming language and putting required comments in between of code.
In R we use #(hash) sign to write a single line comment and R does not support multiline comments.
Now we’ll see how to perform basic arithmetic operations in R. It is quite simple like using the calculator as no code is required to add, subtract or multiply.
See the example given below and try the code in R GUI software.
#Add Operation 10+12 #Subtract Operation 12-10 #Multiplication 10*12 #Divison 20/10 # Exponentiation 3^3 # Modulo 25%%4
And see the output in R GUI
and you can see that comments are written in code using # sign.
Print Hello World in R
The first program of every programming language is printing “Hello World” on the screen so here we’ll see how to write our first program in R.
Here we take a variable sayHello and use <- to assign the value to the variable and to print this variable on the console, use the print command as shown in below code.
#Set value in a variable sayHello <- "Hello World in R Programming!" #Put this command to print print(sayHello)
And output in R console – It is printing “Hello World in R Programming”
So this post gives a basic idea about R programming, Now in next post, we’ll learn about variables and data-types used in R language.
An Oracle ACE, Blogger, Reviewer, Technical Lead working on Oracle ADF