Created
June 7, 2018 17:24
-
-
Save byanuaria/997470b6e5a140263476d9592bb5d56b to your computer and use it in GitHub Desktop.
3 functions to find the hospital with the best rates for heart attacks, heart failures, and pneumonia
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
## find the hospital for state with best heart attack rate | |
ha <- function(thestate) { | |
data <- read.csv("outcome-of-care-measures.csv", | |
header = TRUE, sep = ",", | |
colClasses = "character") | |
# convert to proper class | |
data[,11] <- as.numeric(data[,11]) | |
for(i in thestate) { | |
# choose the state | |
mystate <- subset(data, State == thestate) | |
# find the hospital | |
myhospital <- as.character(mystate[which.min(mystate[,11]), 2]) | |
} | |
myhospital | |
} | |
## find the hospital for state with best heart failure rate | |
hf <- function(thestate) { | |
data <- read.csv("outcome-of-care-measures.csv", | |
header = TRUE, sep = ",", colClasses = "character") | |
# convert hf class to numeric | |
data[,17] <- as.numeric(data[,17]) | |
for(i in thestate) { | |
mystate <- subset(data, State == thestate) | |
ind <- which.min(mystate[,17]) | |
myhospital <- (mystate[ind, 2]) | |
} | |
myhospital | |
} | |
## find the hospital for state with best pneumonia rates | |
pneu <- function(thestate) { | |
data <- read.csv("outcome-of-care-measures.csv", | |
header = TRUE, sep = ",", colClasses = "character") | |
# convert pneumonia column to numeric | |
data[,23] <- as.numeric(data[,23]) | |
for(i in thestate) { | |
mystate <- subset(data, State == thestate) | |
ind <- which.min(mystate[,23]) | |
myhospital <- mystate[ind, 2] | |
} | |
myhospital | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment