Working on if, else, else if statements.

x <- 6
if(x%%2==0){
  print("Even no.")
}else{
  print("Not Even")
}
## [1] "Even no."

Checking if varibale is a matrix.

x <- matrix(1:10)
if(is.matrix(x) == TRUE) {
  print("Is a matrix")
}else{
  print("Not a matrix")
}
## [1] "Is a matrix"

Arranging elements in desending order.

x <- c(9,2,7)
if(x[1] > x[2]){
  # if first is larger than second.
  a <- x[1]
  b <- x[2]
}else{
  a <- x[2]
  b <- x[1]
}
# When third is the largest.
if(x[3] > a & x[3] > b){
  a <- x[3]
  b <- x[1]
  c <- x[2]
}else if (x[3] < a & x[3] < b){  
  # when third is the smallest.
  c <- x[3]
}else{
  a <- x[1]
  b <- x[3]
  c <- x[2]
}
print(paste(a, b, c))
## [1] "9 7 2"

Trying to only print the maximum element.

x <- c(24, 10, 9)
if(x[1] > x[2] & x[1] > x[3]){
  x[1]
}else if(x[2] > x[1] & x[2] > x[3]){
  x[2]
}else{
  x[3]
}
## [1] 24