mercredi 29 septembre 2021

Making a function -- R error says "Error: unexpected '}' in "}""

I am making a function where I am trying to get R to take in a vector then print out a phrase depending on the number input.

for example, if I have the vector

x <- c(4,2,7,9,10,5,2,1,4,6,8,10)

I want R to say "troubled" for numbers between 1-5, "potentially troubled" for numbers between 6-7, and "not troubled" for numbers between 8-10.

The dataset I have only has numbers between 1-10. This is what I have right now:

pls <- function(x){
if(5>=x){
  print("Troubled")
} else if(8>x>5){
  print("Potentially troubled")
} else if(x>=8){
  print("Not troubled")
}
}

the error message I am getting says:

Error: unexpected '}' in "}"

I do not understand why it is not running

Aucun commentaire:

Enregistrer un commentaire