Suppose you're asked to write an if-else statement in R that checks if a number is positive or negative. How would you do it?

  • if (number > 0) { code for positive number } else { code for negative number }
  • if (number >= 0) { code for positive number } else { code for negative number }
  • if (number == 0) { code for positive number } else { code for negative number }
  • if (number != 0) { code for positive number } else { code for negative number }
To write an if-else statement in R that checks if a number is positive or negative, you can use the condition if (number > 0) { code for positive number } else { code for negative number }. If the number is greater than 0, the code inside the if block will be executed; otherwise, the code inside the else block will be executed.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *