vendredi 22 mai 2020

How to use if statement in R?

I am habituated to python where the following code works without any exceptions. However, I am getting the below error in R when I try to run the command.

a <- readline(prompt="Give a num between 1-10: ")
b <- readline(prompt="Give another between 11-20: ")

if((1 <= a <= 10) & (11 <= b <= 20)) {
  a <- a
  b <- b
} else {
  a <- readline(prompt="Give a correct num between 1-10: ")
  b <- readline(prompt="Give a correct num between 11-20: ")
}

Can someone please help me out with this?

enter image description here

Aucun commentaire:

Enregistrer un commentaire