Hello Data Experts,
Let me continue from my last blog “Guide to install R and R Studio” where I had shared features for R Studio on windows platform. Now that we are ready and familiar with R Studio, next steps are to make our-self comfortable with R Programming.
Let me start with a statement R programing is very much like how we operate calculator. We can also call R as a glorified calculator to start with.
Few basic tips to keep in mind while working on R:
- Comments start with “#” character.
- No need to declare variable, assigning a value to a variable directly will work. Assignment of a value to a variable is done by left assign.
- Please note there are 3 ways to assign a variable
- Right Assign 25 -> b
- Left Assign a <- 1 (Left assign is the best practice for R programing to do value assignment).
- Assign operator c = 24
- Help can be invoked by prefixing “?” character.
- Data Type is assigned by R internally based on the value assigned to the variable.
- St <- “How are you”
- Bi <- TRUE
- Nu <- 1
- R programming language is case sensitive, these are 2 different variables.
- uc <- “LOWERCASE”
- UC <- “UPPERCASE”
- R accepts “.” Character in variables, hence no need to have variable with underscore.
- Height.inch <- 23
Let us start with Data Operators “SUM”, “SUBSTRACTION”, “MULTIPLICATION” and “DIVISION”.
First assign values to variables
FV <- 2
SV <- 6
TV <- 3
FV + SV
# FV + SV will result 8
SV – TV
# SV – TV will result 3
# SV/TV will result 2
# FV*TV will result 6
Let us use advanced operator, POWER, REMAINDER and QUOTIENT
# TV^FV will result 9, as it will be calculated as 3 to the power 2.
# This will result 1
QUOTIENT > DIVISION ADJUSTED TO WHOLE LFET
# This will result 1
Let us star using relation operator for comparison , !=, ==, =. We can also mix and match these operators.
a <- 4
b <- 9
a > b # This will FALSE
a != b # This will TRUE
a == b # This will FALSE
a = b # This will FALSE
a => b # This is not the right syntax hence will error out.
I am sure this blog was useful and must have helped you understand “How to use basic Operators using R”. With this we are all set to go head and start practicing advance R using RStudio. In my next blog, I will begin with “Advanced R using R Studio”.
I had kept this session light as it is important to have basics clear. Thank you being with me for this blog I hope it was helpful. Kindly share your valuable and kind opinion. Please do not forget to suggest what you would like to understand and hear from me in my future blogs.