Professional Documents
Culture Documents
R-Variables
Code:
A = c(0,1,2,3)
B <- c("Hello","World")
c(TRUE,1) -> C
print(A)
Output:
[1] 0 1 2 3
A is 0 1 2 3
B is Hello World
C is 1 1
If Statement
Code:
x <- 30L
if(is.integer(x)) {
print("I am Studying PGDM")
}
Output:
[1] "I am Studying PGDM"
If….Else Statement
Code:
x <- c("I'm","very","happy")
if("happy" %in% x)
{
print("Happiest")
} else {
print("Not Happy")
}
Output:
[1] "Happiest"
Switch Statement
Code:
x <- switch(
3,
"IT",
"Marketing",
"HR",
"Finance"
)
print(x)
Output:
[1] "HR"