В разделе «сердечная недостаточность» я пытаюсь выполнить действие заголовка. Я передаю число 3 аргументу, а затем сортирую данные, после чего использую это число для выбора строки, но безуспешно.
best("AK","pneumonia", 3)
best <- function(state, outcome, num) {
#read file function
#Reads the csv file
dataTable <- read.csv("outcome.csv", header = TRUE, stringsAsFactors = FALSE)
#Passes the state argument to the choice variable
choice <- state
#selects all rows which match the state that was selected
stateOfChoice <- dataTable[dataTable$State == "AK",]
#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$Hospital.30.Day.Death..Mortality..Rates.from.Heart.Attack),]
heart_attack
hospital <- heart_attack$Hospital.Name
hospital
return(hospital)
}
#Similar as above, but instead with heart failure
else if (outcome == "heart failure"){
?order
orderState <- stateOfChoice[order(as.integer(stateOfChoice$Hospital.30.Day.Death..Mortality..Rates.from.Heart.Failure),decreasing = FALSE),]
orderState
#orderStateNum <- orderState$Hospital.30.Day.Death..Mortality..Rates.from.Heart.Failure[[num]]
orderStateNum <- subset(orderState,Hospital.30.Day.Death..Mortality..Rates.from.Heart.Failure == num)
orderStateNum
##heart_failure <- stateOfChoice[which.min(stateOfChoice$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$Hospital.30.Day.Death..Mortality..Rates.from.Pneumonia),]
pneumonia
hospital <- pneumonia$Hospital.Name
return(hospital)
}
}
Вот данные:
Пожалуйста, нажмите, чтобы получить данные