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

Recent Comments

ResearchHUB

A platform to support academics particularly young researchers. ResearchHUB provides training on different research methods, and academic writing and publishing in peer-reviewed journals.

Team ResearchHUB

NEWSLETTER