if else in r in r

The syntax of if-else control structure in R is:

main.r
if (condition) {
  # Statements to execute if the condition is TRUE
} else {
  # Statements to execute if the condition is FALSE
}
131 chars
6 lines

Here's an example of how to use if-else:

main.r
# Assign a value to x
x <- 5

# Use if-else to check if x is greater than 10
if (x > 10) {
  print("x is greater than 10.")
} else {
  print("x is less than or equal to 10.")
}
177 chars
10 lines

Output:

main.r
[1] "x is less than or equal to 10."
37 chars
2 lines

In the above code, the condition x > 10 is evaluated. Since 5 is not greater than 10, the statements inside the else block are executed, and the message "x is less than or equal to 10." is printed to the console.

gistlibby LogSnag