-
Notifications
You must be signed in to change notification settings - Fork 0
/
rankhospital.r
41 lines (39 loc) · 1.21 KB
/
rankhospital.r
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
38
39
40
41
rankhospital <- function(state, outcome, num = "best")
{
dat<-read.csv("outcome-of-care-measures.csv")
temp<-split(dat,dat["State"])
if(sum(state==dat["State"])!=0)
{
b<-temp[state]
if (outcome=="heart attack")
{ x<-as.numeric(levels(b[[1]][,11])[b[[1]][,11]])
y<-b[[1]][order(x,b[[1]][,2],na.last=NA),]
if(num=="best")
{as.vector(y[1,2])}
else if(num=="worst")
{as.vector(tail(y[,2],n=1L))}
else {as.vector(y[num,2])}
}
else
{if (outcome=="heart failure")
{ x<-as.numeric(levels(b[[1]][,17])[b[[1]][,17]])
y<-b[[1]][order(x,b[[1]][,2],na.last=NA),]
if(num=="best")
{as.vector(y[1,2])}
else if(num=="worst")
{as.vector(tail(y[,2],n=1L))}
else {as.vector(y[num,2])}
}
else {
if (outcome=="pneumonia")
{ x<-as.numeric(levels(b[[1]][,23])[b[[1]][,23]])
y<-b[[1]][order(x,b[[1]][,2],na.last=NA),]
if(num=="best")
{as.vector(y[1,2])}
else if(num=="worst")
{as.vector(tail(y[,2],n=1L))}
else {as.vector(y[num,2])}}
else stop("invalid outcome")}}
}
else stop("invalid state")
}