samedi 26 juin 2021

Function with a nested loop in R

I'm trying to write a function that returns "Fail" if all 3 valves at a given location (x) are open (1), but returns "Pass" if any valve is closed (0). My code is below, but it doesn't work and I get the error---unexpected 'else' in:"else"--- And I can't figure out where my code is wrong.

systemFail <- function(x) {
  
if(df$valveOne[df$location == x] == 1) {        
    if(df$valveTwo[df$location == x] == 1) {  
      if(df$valveThree[df$location == x] == 1) {
        print("Fail")}}}
      else {            
        print ("Pass")}
    else {            
    Print("Pass")}
else {
  Print("Pass")}
}

Aucun commentaire:

Enregistrer un commentaire