-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbest.R
More file actions
26 lines (20 loc) · 887 Bytes
/
best.R
File metadata and controls
26 lines (20 loc) · 887 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
best <- function(state, outcome) {
Outcome.name <- c("heart attack", "heart failure", "pneumonia")
Outcome.col <- c(11, 17, 23)
foo <- data.frame(Outcome.name, Outcome.col)
## Check if outcome is valid
if(!(outcome %in% foo[,1])) stop("invalid outcome")
foo <- subset(foo, Outcome.name == outcome)
## Read outcome data
data <- read.csv("outcome-of-care-measures.csv", colClasses = "character")
## Check if state is valid
if(!(state %in% data[, 7])) stop("invalid state")
state.data <- subset(data, data[, 7] == state)
## Remove hospitals without data
state.data[, foo[,2]] <- as.numeric(state.data[, foo[,2]])
state.data <- state.data[complete.cases(state.data[, foo[,2]]),]
## Return hospital name in that state with lowest 30-day death
## rate
state.data <- state.data[ order(state.data[,foo[,2]], state.data[,2]), ]
state.data[1,2]
}