0

What is an efficient way to describe three different cases for x<y, x>y and x=y? Here x and y are two numbers. I thought the following:

if (x<y) {
  ...
}
if (x>y) {
  ...
}
if (x=y) {
  ...
}

Maybe I could use ifelse statement?

Mark
  • 1,577
  • 16
  • 43
  • you can have a look at `?dplyr::case_when` but mostly it depends on your use-case. A specific example would have been helpful. – Ronak Shah Oct 01 '19 at 07:23

1 Answers1

1

The else-if construction should be on the same line as the last brace of the preceding block.
The ifelse function is probably not what you're looking for if you're looking to execute multiple statements.

if (x<y) {
  ...
} else if (x>y) {
  ...
} else if (x=y) {
  ...
}
greysaff
  • 198
  • 1
  • 9