Introduction to R (Part 1): Data operators in R

#Specifying a variable
#here, variable refer to a reserved memory to store values
a=30
b=”Welcome to Research HUB”
c= TRUE
d= 15

#Data operators (5 categories)
#Arithmetic operators (+, -, *, /, ^, %%, %/%)
a+d
a-d
a*d
a/d
a^2
a%%d #%% gives reminder after division
a%/%d #%/% gives round-up dividing number

 

#Assignment operator (=, <-, <<-, ->, ->>)
100->>e
f<<-90

 

#Relational operator (>, <, ==, !=)
e>f
e<f
e==f
e!=f # != mean ‘not equal’
e>=f #combining > & =
e<=f #combining < & =

 

#Logical operator (&, |, !)
g=T
h=F

g & h # & operator gives True only if both are True
g & g

g | h # | (or) operator gives True if any is True

!g # ! (not) operator gives opposite of present value

 

#Special operator (:, %in %)
i =1:20 # : (range) operator gives integer values within a given range
i #to see the range of integers in ‘i’ variable
10 %in% i #to check whether a value exists within h

############################################################
#To clear Console press Ctrl+L

Leave your thoughts

The ResearchHUB

A platform to support quality academic research. The goal is to raise awareness among young students and researchers about the need of good research, and guide them to achieve excellence in academia. The platform is run by a team of aspiring PhD students residing in many different countries of the world.

NEWSLETTER