Skip to content
Prev 377803 / 398503 Next

Help with if else branching print out

Hello,

Yet another option is ?cat.


msg <- c("is not between 1 or 15",
          "is *not* 6 - 9 inclusive, nor is it 12",
          "falls within 6 - 9 inclusively, or is 12",
          "is *not* 6 - 9 inclusive, nor is it 12",
          "is not between 1 or 15")

nums <- as.numeric(readline("Please enter a number between 1 and 15: "))

i <- if(nums == 12) 2 else findInterval(nums, c(-Inf, 1, 6, 9, 15), 
rightmost.closed = TRUE)
cat(nums, msg[i], "\n")


Hope this helps,

Rui Barradas

?s 09:25 de 18/12/2018, Ivan Krylov escreveu: