Here we are explaining how to write an R program to implement the if-else statement. Here we are using a control statement if-else for checking. The if-else statement helps to check the condition based on the condition the expression is performed. The syntax of if-else statement is like,
Below are the steps used in the R program to implement the if-else statement. In this R program, we first create a vector quantity and assign it with a value of 50. Check the value of quantity using if-else the statement. Based on the condition print the corresponding statement.
# Create vector quantity
quantity <- 50
# Set the is-else statement
if (quantity > 40) {
print('Great you sold a lot!')
} else {
print('Not enough for today')
}
## [1] "Great you sold a lot!"
# Create vector quantity
quantity <- 50
# Set the is-else statement
if (quantity > 60) {
print('Great you sold a lot!')
} else {
print('Not enough for today')
}
## [1] "Not enough for today"