Coursera Computing in Data Analysis Assignment 2 Part 5-7 Week 4

Background

The data for this assignment come from the Hospital Compare web site (http://hospitalcompare.hhs.gov) run by the U.S. Department
of Health and Human Services. The purpose of the web site is to provide data and information about the quality of care at over
FOUR THOUSAND (4,000) Medicare-certied hospitals in the U.S. This dataset essentially covers all major U.S. hospitals. This
dataset is used for a variety of purposes, including determining whether hospitals should be fined for not providing high quality
care to patients (see http://goo.gl/jAXFX for some background on this particular topic).

The Hospital Compare web site contains a lot of data and we will only look at a small subset for this assignment. The zip file
for this assignment contains THREE (3) files:

(1) outcome-of-care-measures.csv: Contains information about THIRTY(30)-day mortality and readmission rates for heart attacks,
heart failure, and pneumonia for over FOUR THOUSAND (4,000) hospitals;

(2) hospital-data.csv: Contains information about each hospital;

(3) Hospital_Revised_Flatfiles.pdf: Descriptions of the variables in each file (i.e the code book).

A description of the variables in each of the files is in the included PDF file named Hospital_Revised_Flatfiles.pdf. This
document contains information about many other files that are not included with this programming assignment. You will want to
focus on the variables for Number NINETEEN (19) (“Outcome of Care Measures.csv”) and Number ELEVEN (11) (“Hospital Data.csv”).
You may find it useful to print out this document (at least the pages for Table NINETEEN (19) and ELEVEN (11)) to have next to
you while you work on this assignment. In particular, the numbers of the variables for each table indicate column indices in
each table (i.e. “Hospital Name” is column TWO (2) in the outcome-of-care-measures.csv file).

Question

(5) Finding the best hospital in a state.

Write a function called best() that takes TWO (2) arguments: (a) the TWO(2)-character abbreviated name of a state; and (b) an
outcome name. The function reads the outcome-of-care-measures.csv file and returns a character vector with the name of the
hospital that has the best (i.e. LOWEST) 30-day mortality for the specified outcome in that state. The hospital name is the name
provided in the Hospital.Name variable. The outcomes can be one of “heart attack”, “heart failure”, or “pneumonia”. The function
should use the following template.

> best <- function(state, outcome) {                                                  
          ## Read outcome data                                                        
          ## Check that state and outcome are valid                                   
          ## Return hospital name in that state with lowest 30-day death rate         
  }                                                                                   

The function should check the validity of its arguments. If an invalid state value is passed to best(), the function should throw
an error via the stop() function with the exact message “invalid state”. If an invalid outcome value is passed to best(), the
function should throw an error via the stop() function with the exact message “invalid outcome”.

Save your code for this function to a file named best.R. To run the test script for this part, make sure your working directory
has the file best.R in it.

(6) Ranking hospitals by outcome in a state.

Write a function called rankhospital() that takes THREE (3) arguments: (a) the TWO(2)-character abbreviated name of a state
(state); (b) an outcome (outcome); and © the ranking of a hospital in that state for that outcome (num). The function reads the
outcome-of-care-measures.csv file and returns a character vector with the name of the hospital that has the ranking specified by
the num argument. For example, the call:

> rankhospital("MD", "heart failure", 5)                                              

would return a character vector containing the name of the hospital with the FIFTH (5th) LOWEST THIRTY(30)-day death rate for
heart failure. The num argument can take values “best”, “worst”, or an integer indicating the ranking (SMALLER numbers are
better). If the number given by num is LARGER THAN the number of hospitals in that state, then the function should return NA. The
function should use the following template.

> rankhospital <- function(state, outcome, num = "best") {                            
                  ## Read outcome data                                                
                  ## Check that state and outcome are valid                           
                  ## Return hospital name in that state with the given rank           
                  ## THIRTY(30)-day death rate                                        
  }                                                                                   

Hospitals that do NOT have data on a particular outcome should be excluded from the set of hospitals when deciding the rankings.

If there is MORE THAN ONE (1) hospital for a given ranking, then the hospital names should be sorted in alphabetical order and the
FIRST (1st) hospital in that set should be returned (i.e. if hospitals “b”, “c”, and “f” are tied for a given rank, then hospital
“b” should be returned).

The function should check the validity of its arguments. If an invalid state value is passed to rankhospital(), the function
should throw an error via the stop() function with the exact message “invalid state”. If an invalid outcome value is passed to
rankhospital(), the function should throw an error via the stop() function with the exact message “invalid outcome”. The num
variable can take values “best”, “worst”, or an integer indicating the ranking (SMALLER numbers are better). If the number given
by num is larger than the number of hospitals in that state, then the function should return NA.

Save your code for this function to a file named rankhospital.R. To run the test script for this part, make sure your working
directory has the file rankhospital.R in it.

(7) Ranking hospitals in all states

Write a function called rankall() that takes TWO (2) arguments: (a) an outcome name (outcome); and (b) a hospital ranking (num).
The function reads the outcome-of-care-measures.csv file and returns a TWO(2)-column data frame containing the hospital in EACH
state that has the ranking specified in num. For example the function call

> rankall("heart attack", "best")                                                     

would return a data frame containing the names of the hospitals that are the best in their respective states for THIRTY(30)-day
heart attack death rates. The function should return a value for EVERY state (some may be NA). The FIRST (1st) column in the data
frame is named hospital, which contains the hospital name, and the SECOND (2nd) column is named state, which contains the
TWO(2)-character abbreviation for the state name. The function should use the following template.

> rankall <-  function(outcome, num = "best") {                                       
              ## Read outcome data                                                    
              ## For each state, find the hospital of the given rank                  
              ## Return a data frame with the hospital names and the (abbreviated)    
              ## state name                                                           
  }                                                                                   

Hospitals that do NOT have data on a particular outcome should be excluded from the set of hospitals when deciding the rankings.

If there is MORE THAN ONE (1) hospital for a given ranking, then the hospital names should be sorted in alphabetical order and
the FIRST (1st) hospital in that set should be returned (i.e. if hospitals “b”, “c”, and “f” are tied for a given rank, then
hospital “b” should be returned).

NOTE: For the purpose of this part of the assignment (and for efficiency), your function should NOT call the rankhospital()
function from the previous section.

The function should check the validity of its arguments. If an invalid outcome value is passed to rankall(), the function should
throw an error via the stop() function with the exact message “invalid outcome”. The num variable can take values “best”, “worst”,
or an integer indicating the ranking (SMALLER numbers are better). If the number given by num is larger than the number of
hospitals in that state, then the function should return NA.

Save your code for this function to a file named rankall.R. To run the test script for this part, make sure your working directory
has the file rankall.R in it.

Grading

This assignment will be graded using unit tests executed via the submit script that you run on your computer. To obtain the submit
script, run the following code in R:

> source("http://spark-public.s3.amazonaws.com/compdata/scripts/submitscript.R")      

The FIRST (1st) time you run the submit script it will prompt you for your Submission login AND Submission password.

To execute the submit script, type

> submit()                                                                            

NOTE that the submit script requires that you be connected to the Internet in order to work properly. When you execute the submit
script in R, you will see the following menu (after typing in your submission login email and password):

[1] 'best' part 1                                                                     
[2] 'best' part 2                                                                     
[3] 'best' part 3                                                                     
[4] 'rankhospital' part 1                                                             
[5] 'rankhospital' part 2                                                             
[6] 'rankhospital' part 3                                                             
[7] 'rankhospital' part 4                                                             
[8] 'rankall' part 1                                                                  
[9] 'rankall' part 2                                                                  
[10] 'rankall' part 3                                                                 
Which part are you submitting [1-10]?                                                 

Entering a number between ONE (1) AND TEN (10) will execute the corresponding part of the homework. We will compare the output of
your functions to the correct output. For EACH test passed you receive the specified number of points on the Assignments List web
page. There are TEN (10) tests to pass (each worth THREE (3) points) for a TOTAL of THIRTY (30) points for the entire assignment.

library(lattice)

#
# |------------------------------------------------------------------------------------------|
# | I N I T I A L I Z A T I O N |
# |------------------------------------------------------------------------------------------|
Init <- function(fileStr, workDirStr = "C:/Users/denbrige/100 FxOption/103 FxOptionVerBack/080 Fx Git/R-source") {
    setwd(workDirStr)
    retDfr <- read.csv(fileStr, colClasses = "character")
    return(retDfr)
}

#
# |------------------------------------------------------------------------------------------|
# | I N T E R N A L F U N C T I O N S |
# |------------------------------------------------------------------------------------------|
rankall <- function(outcomeChr, rankObj = "best") {
    # --- Init loading outcome data
    outcomeDfr <- Init("ProgAssignment2-data/outcome-of-care-measures.csv")

    # --- Coerce character into numeric
    suppressWarnings(outcomeDfr[, 11] <- as.numeric(outcomeDfr[, 11]))
    suppressWarnings(outcomeDfr[, 17] <- as.numeric(outcomeDfr[, 17]))
    suppressWarnings(outcomeDfr[, 23] <- as.numeric(outcomeDfr[, 23]))

    # --- Create a data frame of freq by state Remove row.names
    tableDfr <- data.frame(State = names(tapply(outcomeDfr$State, outcomeDfr$State, 
        length)), Freq = tapply(outcomeDfr$State, outcomeDfr$State, length))
    rownames(tableDfr) <- NULL

    # --- Create a data frame of possible inputs and respective columns
    inputDfr <- data.frame(Outcome = c("heart attack", "heart failure", "pneumonia"), 
        Col = c(11, 17, 23))

    # --- Check that outcome is valid
    if (nrow(inputDfr[inputDfr$Outcome == outcomeChr, ]) == 0) 
        stop("invalid outcome")

    # --- Assert create an empty vector Add column rank for debug
    nameChr <- character(0)
    # rankChr <- character(0)

    # --- Return hospital name in that state with the ranked THIRTY(30)-day
    # death rate Create a data frame with given ONE (1) state Determine the
    # relevant column Reorder the new data frame from best to worst
    for (stateChr in tableDfr$State) {
        stateDfr <- outcomeDfr[outcomeDfr$State == stateChr, ]
        colNum <- inputDfr[inputDfr$Outcome == outcomeChr, 2]
        stateDfr <- stateDfr[complete.cases(stateDfr[, colNum]), ]
        stateDfr <- stateDfr[order(stateDfr[, colNum], stateDfr$Hospital.Name), 
            ]

        # --- Convert 'best' and 'worst' to numeric Determine the relevant row
        if (rankObj == "best") 
            rankNum <- 1 else if (rankObj == "worst") 
            rankNum <- nrow(stateDfr) else suppressWarnings(rankNum <- as.numeric(rankObj))

        # --- Append hospital name to character vector
        nameChr <- c(nameChr, stateDfr[rankNum, ]$Hospital.Name)
        # rankChr <- c( rankChr, rankNum )
    }

    # --- Return value is a data frame (hospital, state)
    return(data.frame(hospital = nameChr, state = tableDfr$State))
}

rankhospital <- function(stateChr, outcomeChr, rankObj) {
    # --- Init loading outcome data
    outcomeDfr <- Init("ProgAssignment2-data/outcome-of-care-measures.csv")

    # --- Coerce character into numeric
    suppressWarnings(outcomeDfr[, 11] <- as.numeric(outcomeDfr[, 11]))
    suppressWarnings(outcomeDfr[, 17] <- as.numeric(outcomeDfr[, 17]))
    suppressWarnings(outcomeDfr[, 23] <- as.numeric(outcomeDfr[, 23]))

    # --- Create a data frame of freq by state Remove row.names
    tableDfr <- data.frame(State = names(tapply(outcomeDfr$State, outcomeDfr$State, 
        length)), Freq = tapply(outcomeDfr$State, outcomeDfr$State, length))
    rownames(tableDfr) <- NULL

    # --- Create a data frame of possible inputs and respective columns
    inputDfr <- data.frame(Outcome = c("heart attack", "heart failure", "pneumonia"), 
        Col = c(11, 17, 23))

    # --- Check that state and outcome are valid
    if (nrow(tableDfr[tableDfr$State == stateChr, ]) == 0) 
        stop("invalid state")
    if (nrow(inputDfr[inputDfr$Outcome == outcomeChr, ]) == 0) 
        stop("invalid outcome")

    # --- Return hospital name in that state with the ranked THIRTY(30)-day
    # death rate Create a data frame with given ONE (1) state Determine the
    # relevant column Reorder the new data frame from best to worst
    stateDfr <- outcomeDfr[outcomeDfr$State == stateChr, ]
    colNum <- inputDfr[inputDfr$Outcome == outcomeChr, 2]
    stateDfr <- stateDfr[complete.cases(stateDfr[, colNum]), ]
    stateDfr <- stateDfr[order(stateDfr[, colNum], stateDfr$Hospital.Name), 
        ]

    # --- Convert 'best' and 'worst' to numeric 'Worst' code is not valid if
    # omit NA from results Determine the relevant row
    if (rankObj == "best") 
        rankObj <- 1
    if (rankObj == "worst") 
        rankObj <- nrow(stateDfr)
    # if( rankObj=='worst' ) rankObj <- tableDfr[tableDfr$State==stateChr, 2]
    suppressWarnings(rankNum <- as.numeric(rankObj))

    # --- Return value is a character Return data frame for debug
    return(stateDfr[rankNum, ]$Hospital.Name)
    # return(stateDfr)
}

best <- function(stateChr, outcomeChr) {
    # --- Init loading outcome data
    outcomeDfr <- Init("ProgAssignment2-data/outcome-of-care-measures.csv")

    # --- Coerce character into numeric
    suppressWarnings(outcomeDfr[, 11] <- as.numeric(outcomeDfr[, 11]))
    suppressWarnings(outcomeDfr[, 17] <- as.numeric(outcomeDfr[, 17]))
    suppressWarnings(outcomeDfr[, 23] <- as.numeric(outcomeDfr[, 23]))

    # --- Create a data frame of freq by state Remove row.names
    tableDfr <- data.frame(State = names(tapply(outcomeDfr$State, outcomeDfr$State, 
        length)), Freq = tapply(outcomeDfr$State, outcomeDfr$State, length))
    rownames(tableDfr) <- NULL

    # --- Create a data frame of possible inputs and respective columns
    inputDfr <- data.frame(Outcome = c("heart attack", "heart failure", "pneumonia"), 
        Col = c(11, 17, 23))

    # --- Check that state and outcome are valid
    if (nrow(tableDfr[tableDfr$State == stateChr, ]) == 0) 
        stop("invalid state")
    if (nrow(inputDfr[inputDfr$Outcome == outcomeChr, ]) == 0) 
        stop("invalid outcome")

    # --- Return hospital name in that state with lowest THIRTY(30)-day death
    # rate Create a data frame with given ONE (1) state Determine the relevant
    # row and column
    stateDfr <- outcomeDfr[outcomeDfr$State == stateChr, ]
    colNum <- inputDfr[inputDfr$Outcome == outcomeChr, 2]
    rowNum <- which.min(stateDfr[, colNum])
    return(stateDfr[rowNum, ]$Hospital.Name)
}

freqVtr <- function(inDfr, orderVtr) {
    # --- Assert 'directory' is a character vector of length 1 indicating the
    # location of the CSV files.  'threshold' is a numeric vector of length 1
    # indicating the number of completely observed observations (on all
    # variables) required to compute the correlation between nitrate and
    # sulfate; the default is 0.  Return a numeric vector of correlations.

    # --- Assert create an empty numeric vector
    outVtr <- numeric(0)

    for (ord in orderVtr) {
        # --- Append numeric vector
        outVtr <- c(outVtr, inDfr[inDfr$State == ord, 2])
    }

    # --- Assert return value is a numeric vector
    return(outVtr)
}

#
# |------------------------------------------------------------------------------------------|
# | M A I N P R O C E D U R E |
# |------------------------------------------------------------------------------------------|

#
# |------------------------------------------------------------------------------------------|
# | P A R T F I V E P R O C E D U R E |
# |------------------------------------------------------------------------------------------|
best("TX", "heart attack")
## [1] "CYPRESS FAIRBANKS MEDICAL CENTER"
best("TX", "heart failure")
## [1] "FORT DUNCAN MEDICAL CENTER"
best("MD", "heart attack")
## [1] "JOHNS HOPKINS HOSPITAL, THE"
best("MD", "pneumonia")
## [1] "GREATER BALTIMORE MEDICAL CENTER"

#
# |------------------------------------------------------------------------------------------|
# | P A R T S I X P R O C E D U R E |
# |------------------------------------------------------------------------------------------|
rankhospital("TX", "heart failure", 4)
## [1] "DETAR HOSPITAL NAVARRO"
rankhospital("MD", "heart attack", "worst")
## [1] "HARFORD MEMORIAL HOSPITAL"
rankhospital("NC", "heart attack", "worst")
## [1] "WAYNE MEMORIAL HOSPITAL"

#
# |------------------------------------------------------------------------------------------|
# | P A R T S E V E N P R O C E D U R E |
# |------------------------------------------------------------------------------------------|
head(rankall("heart attack", 20), 10)
##                               hospital state
## 1                                 <NA>    AK
## 2       D W MCMILLAN MEMORIAL HOSPITAL    AL
## 3    ARKANSAS METHODIST MEDICAL CENTER    AR
## 4  JOHN C LINCOLN DEER VALLEY HOSPITAL    AZ
## 5                SHERMAN OAKS HOSPITAL    CA
## 6             SKY RIDGE MEDICAL CENTER    CO
## 7              MIDSTATE MEDICAL CENTER    CT
## 8                                 <NA>    DC
## 9                                 <NA>    DE
## 10      SOUTH FLORIDA BAPTIST HOSPITAL    FL
tail(rankall("pneumonia", "worst"), 3)
##                                      hospital state
## 52 MAYO CLINIC HEALTH SYSTEM - NORTHLAND, INC    WI
## 53                     PLATEAU MEDICAL CENTER    WV
## 54           NORTH BIG HORN HOSPITAL DISTRICT    WY
tail(rankall("heart failure"), 10)
##                                                             hospital state
## 45                         WELLMONT HAWKINS COUNTY MEMORIAL HOSPITAL    TN
## 46                                        FORT DUNCAN MEDICAL CENTER    TX
## 47 VA SALT LAKE CITY HEALTHCARE - GEORGE E. WAHLEN VA MEDICAL CENTER    UT
## 48                                          SENTARA POTOMAC HOSPITAL    VA
## 49                            GOV JUAN F LUIS HOSPITAL & MEDICAL CTR    VI
## 50                                              SPRINGFIELD HOSPITAL    VT
## 51                                         HARBORVIEW MEDICAL CENTER    WA
## 52                                    AURORA ST LUKES MEDICAL CENTER    WI
## 53                                         FAIRMONT GENERAL HOSPITAL    WV
## 54                                        CHEYENNE VA MEDICAL CENTER    WY
rankall("pneumonia", "worst")
##                                       hospital state
## 1                 ALASKA NATIVE MEDICAL CENTER    AK
## 2                  JACKSONVILLE MEDICAL CENTER    AL
## 3                  RIVER VALLEY MEDICAL CENTER    AR
## 4               HAVASU REGIONAL MEDICAL CENTER    AZ
## 5               DELANO REGIONAL MEDICAL CENTER    CA
## 6         ST MARYS HOSPITAL AND MEDICAL CENTER    CO
## 7                        MILFORD HOSPITAL, INC    CT
## 8               GEORGETOWN UNIVERSITY HOSPITAL    DC
## 9        CHRISTIANA CARE HEALTH SERVICES, INC.    DE
## 10        SEVEN RIVERS REGIONAL MEDICAL CENTER    FL
## 11            MCDUFFIE REGIONAL MEDICAL CENTER    GA
## 12            GUAM MEMORIAL HOSPITAL AUTHORITY    GU
## 13                MAUI MEMORIAL MEDICAL CENTER    HI
## 14                       BURGESS HEALTH CENTER    IA
## 15                 BEAR LAKE MEMORIAL HOSPITAL    ID
## 16                           ST JOHNS HOSPITAL    IL
## 17 INDIANA UNIVERSITY HEALTH LA PORTE HOSPITAL    IN
## 18              WESTERN PLAINS MEDICAL COMPLEX    KS
## 19                     CALDWELL MEDICAL CENTER    KY
## 20           TERREBONNE GENERAL MEDICAL CENTER    LA
## 21                     ATHOL MEMORIAL HOSPITAL    MA
## 22                      CIVISTA MEDICAL CENTER    MD
## 23                          MID COAST HOSPITAL    ME
## 24                 ASPIRUS GRAND VIEW HOSPITAL    MI
## 25                      GLACIAL RIDGE HOSPITAL    MN
## 26          UNIVERSITY OF MISSOURI HEALTH CARE    MO
## 27                      BOLIVAR MEDICAL CENTER    MS
## 28                     GLENDIVE MEDICAL CENTER    MT
## 29                   VIDANT EDGECOMBE HOSPITAL    NC
## 30                    OAKES COMMUNITY HOSPITAL    ND
## 31                 MEMORIAL COMMUNITY HOSPITAL    NE
## 32               LAKES REGION GENERAL HOSPITAL    NH
## 33              BERGEN REGIONAL MEDICAL CENTER    NJ
## 34                                UNM HOSPITAL    NM
## 35              RENOWN REGIONAL MEDICAL CENTER    NV
## 36                    ONEIDA HEALTHCARE CENTER    NY
## 37          COSHOCTON COUNTY MEMORIAL HOSPITAL    OH
## 38                MERCY MEMORIAL HEALTH CENTER    OK
## 39                           BAY AREA HOSPITAL    OR
## 40           POTTSTOWN MEMORIAL MEDICAL CENTER    PA
## 41                HOSPITAL SAN CARLOS BORROMEO    PR
## 42                   SOUTH COUNTY HOSPITAL INC    RI
## 43            LAURENS COUNTY HEALTHCARE SYSTEM    SC
## 44               HURON REGIONAL MEDICAL CENTER    SD
## 45              ATHENS REGIONAL MEDICAL CENTER    TN
## 46                    LIMESTONE MEDICAL CENTER    TX
## 47                         CASTLEVIEW HOSPITAL    UT
## 48                      SENTARA LEIGH HOSPITAL    VA
## 49           ROY LESTER SCHNEIDER HOSPITAL,THE    VI
## 50                        PORTER HOSPITAL, INC    VT
## 51                      OLYMPIC MEDICAL CENTER    WA
## 52  MAYO CLINIC HEALTH SYSTEM - NORTHLAND, INC    WI
## 53                      PLATEAU MEDICAL CENTER    WV
## 54            NORTH BIG HORN HOSPITAL DISTRICT    WY
rankall("heart attack", "best")
##                                    hospital state
## 1          PROVIDENCE ALASKA MEDICAL CENTER    AK
## 2                  CRESTWOOD MEDICAL CENTER    AL
## 3                   ARKANSAS HEART HOSPITAL    AR
## 4                      MAYO CLINIC HOSPITAL    AZ
## 5         GLENDALE ADVENTIST MEDICAL CENTER    CA
## 6      ST MARYS HOSPITAL AND MEDICAL CENTER    CO
## 7                        WATERBURY HOSPITAL    CT
## 8                       PROVIDENCE HOSPITAL    DC
## 9         BAYHEALTH - KENT GENERAL HOSPITAL    DE
## 10               MOUNT SINAI MEDICAL CENTER    FL
## 11                 STEPHENS COUNTY HOSPITAL    GA
## 12         GUAM MEMORIAL HOSPITAL AUTHORITY    GU
## 13                      HILO MEDICAL CENTER    HI
## 14              MARY GREELEY MEDICAL CENTER    IA
## 15                  PORTNEUF MEDICAL CENTER    ID
## 16                    SAINT JOSEPH HOSPITAL    IL
## 17   ST VINCENT HEART CENTER OF INDIANA LLC    IN
## 18                    KANSAS HEART HOSPITAL    KS
## 19        ST ELIZABETH MEDICAL CENTER NORTH    KY
## 20                ST FRANCIS MEDICAL CENTER    LA
## 21     BETH ISRAEL DEACONESS MEDICAL CENTER    MA
## 22              JOHNS HOPKINS HOSPITAL, THE    MD
## 23                            YORK HOSPITAL    ME
## 24                    MUNSON MEDICAL CENTER    MI
## 25                        ST MARYS HOSPITAL    MN
## 26                    BOONE HOSPITAL CENTER    MO
## 27                    WESLEY MEDICAL CENTER    MS
## 28                    BENEFIS HOSPITALS INC    MT
## 29       CAROLINAS MEDICAL CENTER-NORTHEAST    NC
## 30             SANFORD MEDICAL CENTER FARGO    ND
## 31           FAITH REGIONAL HEALTH SERVICES    NE
## 32                  CATHOLIC MEDICAL CENTER    NH
## 33             EAST ORANGE GENERAL HOSPITAL    NJ
## 34                      ST VINCENT HOSPITAL    NM
## 35      SUNRISE HOSPITAL AND MEDICAL CENTER    NV
## 36                     NYU HOSPITALS CENTER    NY
## 37                     JEWISH HOSPITAL, LLC    OH
## 38            OKLAHOMA HEART HOSPITAL SOUTH    OK
## 39               PORTLAND VA MEDICAL CENTER    OR
## 40                      DOYLESTOWN HOSPITAL    PA
## 41        HOSPITAL DR CAYETANO COLL Y TOSTE    PR
## 42                          MIRIAM HOSPITAL    RI
## 43                      MUSC MEDICAL CENTER    SC
## 44 AVERA HEART HOSPITAL OF SOUTH DAKOTA LLC    SD
## 45    METHODIST MEDICAL CENTER OF OAK RIDGE    TN
## 46         CYPRESS FAIRBANKS MEDICAL CENTER    TX
## 47            DIXIE REGIONAL MEDICAL CENTER    UT
## 48       CHESAPEAKE REGIONAL MEDICAL CENTER    VA
## 49        ROY LESTER SCHNEIDER HOSPITAL,THE    VI
## 50       FLETCHER ALLEN HOSPITAL OF VERMONT    VT
## 51   PROVIDENCE SACRED HEART MEDICAL CENTER    WA
## 52                    BELLIN MEMORIAL HSPTL    WI
## 53       MONONGALIA COUNTY GENERAL HOSPITAL    WV
## 54                   WYOMING MEDICAL CENTER    WY
rankall("heart failure", "best")
##                                                             hospital state
## 1                                           SOUTH PENINSULA HOSPITAL    AK
## 2                                 GEORGE H. LANIER MEMORIAL HOSPITAL    AL
## 3                       VA CENTRAL AR. VETERANS HEALTHCARE SYSTEM LR    AR
## 4                               BANNER GOOD SAMARITAN MEDICAL CENTER    AZ
## 5                                  CENTINELA HOSPITAL MEDICAL CENTER    CA
## 6                                          PARKER ADVENTIST HOSPITAL    CO
## 7                                            YALE-NEW HAVEN HOSPITAL    CT
## 8                                                PROVIDENCE HOSPITAL    DC
## 9                                  BAYHEALTH - KENT GENERAL HOSPITAL    DE
## 10                         FLORIDA HOSPITAL HEARTLAND MEDICAL CENTER    FL
## 11                                                  DOCTORS HOSPITAL    GA
## 12                                  GUAM MEMORIAL HOSPITAL AUTHORITY    GU
## 13                                            KUAKINI MEDICAL CENTER    HI
## 14                               MERCY MEDICAL CENTER - CEDAR RAPIDS    IA
## 15                            SAINT ALPHONSUS MEDICAL CENTER - NAMPA    ID
## 16                                    RUSH UNIVERSITY MEDICAL CENTER    IL
## 17                                         ST CATHERINE HOSPITAL INC    IN
## 18                                               HAYS MEDICAL CENTER    KS
## 19                                        WESTLAKE REGIONAL HOSPITAL    KY
## 20                                    WILLIS KNIGHTON MEDICAL CENTER    LA
## 21                                     ST ELIZABETH'S MEDICAL CENTER    MA
## 22                                   MEDSTAR GOOD SAMARITAN HOSPITAL    MD
## 23                MILES MEMORIAL HOSPITAL (LINCOLN COUNTY HEALTHCARE    ME
## 24                                        HARPER UNIVERSITY HOSPITAL    MI
## 25                        ESSENTIA HEALTH ST JOSEPH'S MEDICAL CENTER    MN
## 26                                        NORTH KANSAS CITY HOSPITAL    MO
## 27                                         SOUTH CENTRAL REG MED CTR    MS
## 28                                      COMMUNITY MEDICAL CENTER INC    MT
## 29                               FIRSTHEALTH MOORE REGIONAL HOSPITAL    NC
## 30                                        ST ALOISIUS MEDICAL CENTER    ND
## 31                                           NEBRASKA HEART HOSPITAL    NE
## 32                                          VALLEY REGIONAL HOSPITAL    NH
## 33                                      EAST ORANGE GENERAL HOSPITAL    NJ
## 34                              LOVELACE REGIONAL HOSPITAL - ROSWELL    NM
## 35                                             MOUNTAINVIEW HOSPITAL    NV
## 36                                  KINGSBROOK JEWISH MEDICAL CENTER    NY
## 37                                                 FAIRVIEW HOSPITAL    OH
## 38                                     DUNCAN REGIONAL HOSPITAL, INC    OK
## 39                                        PORTLAND VA MEDICAL CENTER    OR
## 40                                    PHILADELPHIA VA MEDICAL CENTER    PA
## 41                                  SAN LUKE'S MEMORIAL HOSPITAL INC    PR
## 42                                                 WESTERLY HOSPITAL    RI
## 43                                           PALMETTO HEALTH BAPTIST    SC
## 44                          AVERA HEART HOSPITAL OF SOUTH DAKOTA LLC    SD
## 45                         WELLMONT HAWKINS COUNTY MEMORIAL HOSPITAL    TN
## 46                                        FORT DUNCAN MEDICAL CENTER    TX
## 47 VA SALT LAKE CITY HEALTHCARE - GEORGE E. WAHLEN VA MEDICAL CENTER    UT
## 48                                          SENTARA POTOMAC HOSPITAL    VA
## 49                            GOV JUAN F LUIS HOSPITAL & MEDICAL CTR    VI
## 50                                              SPRINGFIELD HOSPITAL    VT
## 51                                         HARBORVIEW MEDICAL CENTER    WA
## 52                                    AURORA ST LUKES MEDICAL CENTER    WI
## 53                                         FAIRMONT GENERAL HOSPITAL    WV
## 54                                        CHEYENNE VA MEDICAL CENTER    WY
rankall("pneumonia", "best")
##                                              hospital state
## 1                  YUKON KUSKOKWIM DELTA REG HOSPITAL    AK
## 2                       MARSHALL MEDICAL CENTER NORTH    AL
## 3                         STONE COUNTY MEDICAL CENTER    AR
## 4                                MAYO CLINIC HOSPITAL    AZ
## 5                         CEDARS-SINAI MEDICAL CENTER    CA
## 6                     EXEMPLA LUTHERAN MEDICAL CENTER    CO
## 7                                SAINT MARYS HOSPITAL    CT
## 8                          WASHINGTON HOSPITAL CENTER    DC
## 9                                BEEBE MEDICAL CENTER    DE
## 10                         MOUNT SINAI MEDICAL CENTER    FL
## 11                          PIEDMONT FAYETTE HOSPITAL    GA
## 12                   GUAM MEMORIAL HOSPITAL AUTHORITY    GU
## 13                           PALI MOMI MEDICAL CENTER    HI
## 14                        MARY GREELEY MEDICAL CENTER    IA
## 15                 ST LUKES WOOD RIVER MEDICAL CENTER    ID
## 16                               LAKE FOREST HOSPITAL    IL
## 17                          INDIANA UNIVERSITY HEALTH    IN
## 18      COMMUNITY HOSPITAL, ONAGA AND ST MARYS CAMPUS    KS
## 19                              CASEY COUNTY HOSPITAL    KY
## 20                     WILLIS KNIGHTON MEDICAL CENTER    LA
## 21                                  FALMOUTH HOSPITAL    MA
## 22                   GREATER BALTIMORE MEDICAL CENTER    MD
## 23 MILES MEMORIAL HOSPITAL (LINCOLN COUNTY HEALTHCARE    ME
## 24                   BEAUMONT HOSPITAL, GROSSE POINTE    MI
## 25                                     MERCY HOSPITAL    MN
## 26                                   LIBERTY HOSPITAL    MO
## 27                         GREENWOOD LEFLORE HOSPITAL    MS
## 28                              BENEFIS HOSPITALS INC    MT
## 29                                       REX HOSPITAL    NC
## 30                      MERCY HOSPITAL OF VALLEY CITY    ND
## 31                         BOX BUTTE GENERAL HOSPITAL    NE
## 32                                EXETER HOSPITAL INC    NH
## 33              ENGLEWOOD HOSPITAL AND MEDICAL CENTER    NJ
## 34                         LOVELACE WESTSIDE HOSPITAL    NM
## 35              SPRING VALLEY HOSPITAL MEDICAL CENTER    NV
## 36                          MAIMONIDES MEDICAL CENTER    NY
## 37                GRANDVIEW HOSPITAL & MEDICAL CENTER    OH
## 38                         HILLCREST HOSPITAL CUSHING    OK
## 39                         PORTLAND VA MEDICAL CENTER    OR
## 40                            KANE COMMUNITY HOSPITAL    PA
## 41                                   HOSPITAL ORIENTE    PR
## 42                                   NEWPORT HOSPITAL    RI
## 43             CAROLINA PINES REGIONAL MEDICAL CENTER    SC
## 44                      SIOUX FALLS VA MEDICAL CENTER    SD
## 45                     UNITED REGIONAL MEDICAL CENTER    TN
## 46 UNIVERSITY OF TEXAS HEALTH SCIENCE CENTER AT TYLER    TX
## 47                                       LDS HOSPITAL    UT
## 48                          NORTON COMMUNITY HOSPITAL    VA
## 49             GOV JUAN F LUIS HOSPITAL & MEDICAL CTR    VI
## 50                    RUTLAND REGIONAL MEDICAL CENTER    VT
## 51                  EVERGREEN HOSPITAL MEDICAL CENTER    WA
## 52                              BELLIN MEMORIAL HSPTL    WI
## 53                             WEIRTON MEDICAL CENTER    WV
## 54                         CHEYENNE VA MEDICAL CENTER    WY

#
# |------------------------------------------------------------------------------------------|
# | E N D O F S C R I P T |
# |------------------------------------------------------------------------------------------|