что означает функция (0) как выход при выполнении функции и что можно сделать? - PullRequest
0 голосов
/ 13 октября 2019

Я добавил комментарии, чтобы объяснить причину синтаксиса. Я получаю выход ниже. Я не совсем уверен, что вызывает этот нежелательный результат. Может ли кто-нибудь объяснить, почему существует фактор (0)?

"фактор (0)

4510 Уровни: МЕДИЦИНСКИЙ ЦЕНТР ABBEVILLE ОБЩЕСТВЕННАЯ БОЛЬНИЦА ABBEVILLE ABBOTT СЕВЕРО-ЗАПАДНАЯ БОЛЬНИЦА ... ZUNI COMPREHENSIVE"

best("CA","heart failure")

best <- function(state, outcome) {
     #read file function

  #Reads the csv file
  dataTable  <- read.csv("outcome.csv", header = TRUE)
  #Passes the state argument to the choice variable
  choice <- state
  #selects all rows which match the state that was selected
  stateOfChoice <- dataTable[which(dataTable$state == choice),]

  #Makes sure that only three of outcomes found in the csv file are selected
  if(outcome != "heart failure" && outcome != "heart attack" && outcome != "pneumonia"){
    print("wrong condition, try again")
    main()
  }

  #using the selected rows from above, return the minimum value of rate from heart attack and then use this selected row to find the hospital name
  else if (outcome == "heart attack"){



    heart_attack <- stateOfChoice[which.min(stateOfChoice$Lower.Mortality.Estimate...Hospital.30.Day.Death..Mortality..Rates.from.Heart.Attack),]
    hospital <- heart_attack$Hospital.Name
    return(hospital)
  }

  #Similar as above, but instead with heart failure
  else if (outcome == "heart failure"){
    heart_failure <- stateOfChoice[which.min(stateOfChoice$Lower.Mortality.Estimate...Hospital.30.Day.Death..Mortality..Rates.from.Heart.Failure),]
    hospital <- heart_failure$Hospital.Name
    return(hospital)
  }

  #Similar as above, but instead with pneumonia
  else if (outcome == "pneumonia"){
    pneumonia <- stateOfChoice[which.min(stateOfChoice$Lower.Mortality.Estimate...Hospital.30.Day.Death..Mortality..Rates.from.Pneumonia),]
    hospital <- pneumonia$Hospital.Name
    return(hospital)
  }

}





main <- function() {
  print("Type Heart Attack, .....")

  outcome <- readline(prompt="Type your selection ")

  print("Select state")

  state <- readline(prompt ="Type in your selection")

  best(state,outcome)
}

main()

Небольшая часть таблицы по строкам и столбцам:

Click Me

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...