#Integer
x<- 2L
typeof(x)
## [1] "integer"
#Double
y<-2.5
typeof(y)
## [1] "double"
#complex
z<-3+2i
typeof(z)
## [1] "complex"
#character
a<-"h"
typeof(a)
## [1] "character"
#logical
q1<-T
q2<-F
#Arthematic operations
A=10
B=5
C=A+B
C
## [1] 15
typeof(c)
## [1] "builtin"
var1=2.5
var2=4
result= var1/var2
result
## [1] 0.625
print(result)
## [1] 0.625
answer<-sqrt(var2)
answer
## [1] 2
greeting<-"Hello"
name<-"sohani"
message<-paste(greeting,name)
message
## [1] "Hello sohani"
#Logical variables and operators
#logical
4<5
## [1] TRUE
10>100
## [1] FALSE
4==5
## [1] FALSE
#list of 10 commonly used logical operations
#== Equal to
#!= Not equal to
#<less than
#> greater than
#<= less than equal to
#>= greater than equal to
#! not
#| or
#& and
# is true(x)
result<-4 <5
result
## [1] TRUE
typeof(result)
## [1] "logical"
result2<-!TRUE
result2<-!(5>1)
result2
## [1] FALSE
result | result2
## [1] TRUE
result & result2
## [1] FALSE
isTRUE(result)
## [1] TRUE
isTRUE(result2)
## [1] FALSE
# the while loop
x<-1
while(x<5)
{
print(x)
x<-x+1
}
## [1] 1
## [1] 2
## [1] 3
## [1] 4
#for loop
for(i in 1:5)
{
print("Hello R")
}
## [1] "Hello R"
## [1] "Hello R"
## [1] "Hello R"
## [1] "Hello R"
## [1] "Hello R"
#Random numbers
rnorm(10)
## [1] -0.60291180 -0.73613845 0.27034375 0.10672996 0.76303123 0.28397703
## [7] 0.83889682 0.00686698 -0.82112466 1.33393170