-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbest.R
More file actions
24 lines (19 loc) · 992 Bytes
/
Copy pathbest.R
File metadata and controls
24 lines (19 loc) · 992 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
best <- function(state, outcome) {
outcome_data <- read.csv("rprog-data-ProgAssignment3-data/outcome-of-care-measures.csv",
stringsAsFactors = FALSE)
if (!any (state == outcome_data$State))
stop("invalid state")
else if (outcome %in% c("heart attack", "heart failure", "pneumonia")
== FALSE)
stop("invalid outcome")
outcome_data <- subset(outcome_data, state == State)
if (outcome == "heart attack") colnum <- 11
else if (outcome == "heart failure") colnum <-17
else colnum <- 23
# filter all the hospitals
outcome_data[ ,colnum] <- suppressWarnings(as.numeric(outcome_data[ ,colnum]))
min_row <- which(outcome_data[ ,colnum] == min(outcome_data[ ,colnum], na.rm = TRUE))
hospitals <- outcome_data[min_row, 2]
hospitals <- sort(hospitals)
return(hospitals)
}