# Mathematical operators
## Session 01

### Addition #Commenting out
1+2
## [1] 3
## Subtraction
9-6
## [1] 3
##Multiplication
5*4
## [1] 20
##Division
10/2
## [1] 5
##Exponentiation
5**2
## [1] 25
5^2
## [1] 25
##Modulo: Returns the remainder after division
4%%2
## [1] 0
5%%2
## [1] 1
8%%3
## [1] 2
(3*5)+6
## [1] 21
3*5+6
## [1] 21
#BODMAS

#Assignment of variables <-

x=3
x<-23  #23 is the age of the respondent
y<-3
z<-x+y
z
## [1] 26
x+y
## [1] 26
##Print the variable x
x
## [1] 23
y
## [1] 3
z
## [1] 26
print(x) ##Prints the variable x
## [1] 23
##Adding assigned variables
y<- 18

x+y
## [1] 41
z<-x+y

z
## [1] 41
##Types of variables

##Numeric/float : 4.567896
##Integer 4
##Logical: Boolean: TRUE. FALSE
##Characters: Text or strings: NSU43

c<- 5.897896
c<-'abc'
d<-"It's my birthday" #use double quotation
class(c)
## [1] "character"
class(d)
## [1] "character"
##Check class of variables
X<- FALSE
class(X)
## [1] "logical"
x<-TRUE

z<-3
class(z)
## [1] "numeric"
a<-"456"
class(a)
## [1] "character"
b<-TRUE
class(b)
## [1] "logical"
##########

##Convert class of variable
x<-5.67
class(x)
## [1] "numeric"
x1<-as.integer(x)
x1
## [1] 5
y<-8
y<-as.integer(y)
class(y)
## [1] "integer"
x1<-as.numeric(x1)
x
## [1] 5.67
x1
## [1] 5
a<-43
a<-as.character(a)
class(a)
## [1] "character"
a<-'abc43' #String
a<-as.numeric(a)
## Warning: NAs introduced by coercion
a<-TRUE
class(a)
## [1] "logical"
a<-as.numeric(a)
a
## [1] 1
a<-as.character(a)
class(a)
## [1] "character"
x<-4.5678
class(x)
## [1] "numeric"
x<-as.integer(x)

x<-as.numeric(x)
x
## [1] 4
#Create a vector

##Numeric vector
x<-5.6 
class(x)
## [1] "numeric"
y<-c(3,4,6,7,8)
y
## [1] 3 4 6 7 8
class(y)
## [1] "numeric"
z<-c(3.4, 7.8, 6.7, 7, 9)
z
## [1] 3.4 7.8 6.7 7.0 9.0
class(z)
## [1] "numeric"
name<-c("Tom","Harry", "Swan")
class(name)
## [1] "character"
name
## [1] "Tom"   "Harry" "Swan"
z[2:4] #consecutive
## [1] 7.8 6.7 7.0
z[c(1,3,5)] #Square brackets are always used for slicing
## [1] 3.4 6.7 9.0
plot(y)

plot(z[1:3])

plot(z[c(2:3,5)])