You are on page 1of 3

Practical No.

R-Variables
Code:
A = c(0,1,2,3)

B <- c("Hello","World")

c(TRUE,1) -> C

print(A)

cat ("A is ", A ,"\n")

cat ("B is ", B ,"\n")

cat ("C is ", C ,"\n")

Output:
[1] 0 1 2 3

A is 0 1 2 3

B is Hello World

C is 1 1

Datatypes Using Variable


Code:
v<- "MBA"
cat("The class of v is ",class(v),"\n")
v <- 34.5
cat(" Now the class of v is ",class(v),"\n")
v<- 27L
cat(" Next the class of v becomes ",class(v),"\n")
Output:
The class of v is character

Now the class of v is numeric

Next the class of v becomes integer


R-Descision Making
R provides 3 types of decision making statements. They are as Follows

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"

You might also like