Skip to content

Instantly share code, notes, and snippets.

@Luckyeva
Last active February 13, 2016 04:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Luckyeva/26e538da3d167285b81e to your computer and use it in GitHub Desktop.
Save Luckyeva/26e538da3d167285b81e to your computer and use it in GitHub Desktop.
## R Programming Assignment 3 - Part I
## Introduction
# Download the file ProgAssignment3-data.zip file containing the data for Programming Assignment 3 from
# the Coursera web site. Unzip the file in a directory that will serve as your working directory. When you
# start up R make sure to change your working directory to the directory where you unzipped the data.
# 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 4,000 Medicare-certified 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 files
# - outcome-of-care-measures.csv: Contains information about 30-day mortality and readmission rates for heart attacks,
# heart failure, and pneumonia for over 4,000 hospitals.
# - hospital-data.csv: Contains information about each hospital.
# - Hospital_Revised_Flatfiles.pdf: Descriptions of the variables in each file (i.e the code book).
## TASKS:
## (1) Plot the 30-day mortality rates for heart attack
## -> (2) Finding the best hospital in a state
## (3) Ranking hospitals by outcome in a state
## (4) Ranking hospitals in all states
## (2) Finding the best hospital in a state
best <- function (state, outcome_name) {
setwd("/Users/lucky1eva/Downloads/rprog-data-ProgAssignment3-data/")
outcome <- read.csv("outcome-of-care-measures.csv")
if (!state %in% State) {
return(print("invalid state"))
} else if (!outcome_name %in% c("heart attack", "heart failure", "pneumonia")) {
return(print("invalid outcome"))
}
State_outcome <- subset(outcome, State == state, select = c("Hospital.Name","State", "Hospital.30.Day.Death..Mortality..Rates.from.Heart.Attack",
"Hospital.30.Day.Death..Mortality..Rates.from.Heart.Failure",
"Hospital.30.Day.Death..Mortality..Rates.from.Pneumonia"))
colnames(State_outcome) <- c("Name","State", "heart attack", "heart failure", "pneumonia")
State_outcome[, 3:5] <- apply(State_outcome[, 3:5], 2, function(x) as.numeric(x))
State_outcome[, 1:2] <- apply(State_outcome[, 1:2], 2, function(x) as.character(x))
outcome_sorted <- State_outcome[order(State_outcome[, outcome_name], State_outcome$Name), ]
list(outcome_sorted[1, 1])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment