#Write an R program that includes different operators, control structures, default values for arguments, returning complex objects.
# if and else
x <- 5
# Check value is less than or greater than 10
if(x > 10){
print(paste(x, "is greater than 10"))
}else{
print(paste(x, "is less than 10"))
}
# Defining matrix
m <- matrix(2:15, 2)
for (r in seq(nrow(m))) {
for (c in seq(ncol(m))) {
print(m[r, c])
}
}
# for loop along with concatenate
for (i in c(-8, 9, 11, 45))
{
print(i)
}
# Default Arguments and complex object return
# 3 as default
divisible <- function(a, b = 3){
if(a %% b == 0)
{
return(paste(a, "is divisible by", b))
}
else
{
return(paste(a, "is not divisible by", b))
}
}
# Function call
divisible(10, 5)
divisible(12)