Last active
June 7, 2018 21:48
-
-
Save byanuaria/b97acb57ec8140556b9a5fba1b783a7c to your computer and use it in GitHub Desktop.
Almost there, but it returns the underlying code of characters instead of the actual numerical value
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
best <- function(thestate, outcome) { | |
mydata <- read.csv("outcome-of-care-measures.csv", header = TRUE, sep = ",", | |
colClasses = "character") | |
for(i in thestate) { | |
if(outcome == "heart attack") { | |
mystate <- subset(mydata, State = thestate, select = c(2, 7, 11)) | |
ind <- which.min(mystate[, 3]) | |
myhospital <- mystate[ind, 1] | |
} else if(outcome == "heart failure") { | |
mystate <- subset(mydata, State = thestate, select = c(2, 7, 17)) | |
ind <- which.min(mystate[, 3]) | |
myhospital <- mystate[ind, 1] | |
} else if(outcome == "pneumonia") { | |
mystate <- subset(mydata, State = thestate, select = c(2, 7, 23)) | |
ind <- which.min(mystate[, 3]) | |
myhospital <- mystate[ind, 1] | |
} else { | |
print("input error") | |
} | |
} | |
myhospital | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
can't figure out how to convert to proper classes.