Skip to content

Instantly share code, notes, and snippets.

@byanuaria
Last active June 7, 2018 21:48
Show Gist options
  • Save byanuaria/b97acb57ec8140556b9a5fba1b783a7c to your computer and use it in GitHub Desktop.
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
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
}
@byanuaria
Copy link
Author

can't figure out how to convert to proper classes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment