-
Notifications
You must be signed in to change notification settings - Fork 0
/
rankall.r
94 lines (87 loc) · 2.06 KB
/
rankall.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
rankall <- function(outcome, num = "best")
{
dat<-read.csv("outcome-of-care-measures.csv")
temp<-split(dat,dat["State"])
y<-NULL
z<-NULL
if (outcome=="heart attack")
{
for (i in 1:54)
{
state<-unique(dat["State"])
b<-temp[as.character(state[i,])]
x<-as.numeric(levels(b[[1]][,11])[b[[1]][,11]])
xo<-b[[1]][order(x,b[[1]][,2],na.last=NA),]
if(num=="best")
{z<-rbind(z,c(as.character(xo[1,2]),as.character(state[i,])))}
else
{
if(num=="worst")
{
z<-rbind(z,c(tail(as.character(xo[,2]),1),as.character(state[i,])))
}
else
{z<-rbind(z,c(as.character(xo[num,2]),as.character(state[i,])))}
}
}
colnames(z)<-c("hospital","state")
z<-as.data.frame(z)
z[order(z["state"]),]
}
else
{
if (outcome=="heart failure")
{
for (i in 1:54)
{
state<-unique(dat["State"])
b<-temp[as.character(state[i,])]
x<-as.numeric(levels(b[[1]][,17])[b[[1]][,17]])
xo<-b[[1]][order(x,b[[1]][,2],na.last=NA),]
if(num=="best")
{z<-rbind(z,c(as.character(xo[1,2]),as.character(state[i,])))}
else
{
if(num=="worst")
{
z<-rbind(z,c(tail(as.character(xo[,2]),1),as.character(state[i,])))
}
else
{z<-rbind(z,c(as.character(xo[num,2]),as.character(state[i,])))}
}
}
colnames(z)<-c("hospital","state")
z<-as.data.frame(z)
z[order(z["state"]),]
}
else
{
if (outcome=="pneumonia")
{ for (i in 1:54)
{
state<-unique(dat["State"])
b<-temp[as.character(state[i,])]
x<-as.numeric(levels(b[[1]][,23])[b[[1]][,23]])
xo<-b[[1]][order(x,b[[1]][,2],na.last=NA),]
if(num=="best")
{z<-rbind(z,c(as.character(xo[1,2]),as.character(state[i,])))}
else
{
if(num=="worst")
{
z<-rbind(z,c(tail(as.character(xo[,2]),1),as.character(state[i,])))
}
else
{z<-rbind(z,c(as.character(xo[num,2]),as.character(state[i,])))}
}
}
colnames(z)<-c("hospital","state")
z<-as.data.frame(z)
z
}
colnames(z)<-c("hospital","state")
z<-as.data.frame(z)
z[order(z["state"]),]
}
}
}