-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbest.R
More file actions
37 lines (32 loc) · 1.14 KB
/
best.R
File metadata and controls
37 lines (32 loc) · 1.14 KB
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
27
28
29
30
31
32
33
34
35
36
37
best <- function(state, outcome)
{
## Read outcome data
readOut <- read.csv("outcome-of-care-measures.csv")
## Check that state and outcome are valid
if(!is.element(state, readOut$State))
{
stop("invalid state")
}
## Return hospital name in that state with lowest 30-day death
finalOutcome <- ".Rates.from";
inOutcome <- strsplit(outcome, split = " ")
inOutcome <- unlist(inOutcome)
for (i in c(1:length(inOutcome)))
{
finalOutcome <-paste(finalOutcome, capitilizeFitstLetter(inOutcome[[i]]), sep = ".")
}
baseName <- "Hospital.30.Day.Death..Mortality";
fullName <- paste(baseName, finalOutcome, sep = ".")
colHospitalName <- which(colnames(readOut) == "Hospital.Name")
colOutcome <- which(colnames(readOut) == fullName)
## rate
stateOutcome <- subset(readOut, readOut$State == state, select = c(colHospitalName, colOutcome))
stateOutcome
stateOutcome
}
capitilizeFitstLetter <- function(x)
{
s <- strsplit(x, " ")[[1]]
paste(toupper(substring(s, 1, 1)), substring(s, 2),
sep = "", collapse = " ")
}