-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDecisionMaking.R
59 lines (48 loc) · 1010 Bytes
/
DecisionMaking.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#Decision Making in R
#********************************************************#
#1. IF STATEMENT
salary <- 300000
if(is.double(salary))
print("Salary is in Double")
#2. IF ELSE STATEMENT
x <- c("I","am","Alive")
if("death" %in% x) { #SubString comparison using "in"
print("Congrats!, You are Alive")
} else {
print("Oops!, You are going to die")
}
#3. SWTICH STATEMENT
x <- switch(
3,
"keeping fine",
"ill",
"severely ill",
"under God's grace"
)
print(paste("You are ",x))
#********************************************************#
#Loops in R
#********************************************************#
#1. REPEAT
v <- c("Hello","loop")
cnt <- 2
repeat {
print(v)
cnt <- cnt+1
if(cnt > 5) {
break
}
}
#2. WHILE
v <- c("Hello","while loop")
cnt <- 2
while (cnt < 7) {
print(v)
cnt = cnt + 1
}
#3. FOR
v <- LETTERS[1:4]
for ( i in v) {
print(i)
}
#********************************************************#