Skip to content

Instantly share code, notes, and snippets.

@byanuaria
byanuaria / Assignment3.3.R
Last active June 7, 2018 21:48
Almost there, but it returns the underlying code of characters instead of the actual numerical value
best <- function(thestate, outcome) {
mydata <- read.csv("outcome-of-care-measures.csv", header = TRUE, sep = ",",
colClasses = "character")
for(i in thestate) {
if(outcome == "heart attack") {
mystate <- subset(mydata, State = thestate, select = c(2, 7, 11))
ind <- which.min(mystate[, 3])
myhospital <- mystate[ind, 1]
@byanuaria
byanuaria / Assignment3.2.R
Created June 7, 2018 17:24
3 functions to find the hospital with the best rates for heart attacks, heart failures, and pneumonia
## find the hospital for state with best heart attack rate
ha <- function(thestate) {
data <- read.csv("outcome-of-care-measures.csv",
header = TRUE, sep = ",",
colClasses = "character")
# convert to proper class
data[,11] <- as.numeric(data[,11])
for(i in thestate) {
@byanuaria
byanuaria / Assignment3.R
Created June 6, 2018 23:07
John Hopkins Introduction to Programming Assignment 3
library(tidyverse)
# read in the data
outcome <- read.table("rprog_data_ProgAssignment3-data/outcome-of-care-measures.csv",
header = TRUE, sep = ",", colClasses = "character")
nrow(outcome)
ncol(outcome)
names(outcome)
# problem 1
# part 1
pollutantmean <- function(directory, pollutant, id = 1:332) {
filelist <- list.files(path = directory, pattern = ".csv",
full.names = TRUE)
values <- numeric()
for(i in id) {