-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworst.R
80 lines (65 loc) · 1.99 KB
/
worst.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
rankhospital <- function(x,y,z) {
statesubset <- outcomes.split[[x]]
statesubset
statenames <- names(outcomes.split)
if (!(x %in% statenames)){
stop("invalid state")
}
index <- as.numeric(which(names(statesubset) == y))
if (length(index) == 0) {
stop("invalid outcome")
} else if (index == 5) {
rank <- 6
} else if (index == 3) {
rank <- 7
} else if (index == 4) {
rank <- 8
} else if (index %in% c(1, 2, 6, 7, 8)) {
stop("invalid outcome")
}
outcome <- select(statesubset, c(1,rank, index))
outcome
}
worstsubset <- rankhospital("CA","Heart Failure", 5)
max(na.omit(worstsubset[, 2]))
####
rankhospital <- function(x,y,num) {
statesubset <- outcomes.split[[x]]
statesubset
statenames <- names(outcomes.split)
if (!(x %in% statenames)){
stop("invalid state")
}
index <- as.numeric(which(names(statesubset) == y))
if (length(index) == 0) {
stop("invalid outcome")
} else if (index == 5) {
rank <- 6
} else if (index == 3) {
rank <- 7
} else if (index == 4) {
rank <- 8
} else if (index %in% c(1, 2, 6, 7, 8)) {
stop("invalid outcome")
}
outcome <- select(statesubset, c(1,rank, index))
# Now to calculate z based of num, including best and worst
if (num == "best") {
z = 1
} else if (num == "worst") {
z = max(na.omit(outcome[,2]))
} else {
z = num
}
output <- outcome[outcome[,2] == z, 1]
finaloutput <- head(output[complete.cases(output)],1)
if (length(finaloutput) == 0) {
print("NA")
}
else finaloutput
}
rankhospital("CA","Heart Failure", 1)
rankhospital("CA","Heart Failure", "best")
rankhospital("CA","Heart Failure", 285)
rankhospital("CA","Heart Failure", 286)
rankhospital("CA","Heart Failure", "worst")