Commits

Ryan Tracey committed 5c7c9d5

week3 finished

Comments (0)

Files changed (2)

coursera/week3/rankall.R

 
 rankall <- function(outcome, num = "best") {
     hdata <- read.csv('outcome-of-care-measures.csv', colClasses = "character")
-
+    #hdata <- read.csv('outcome-of-care-measures.csv')
     # valid outcome?
     if (outcome == "heart attack") {
         colnum <- 11
 
     states <- names(table(hdata$State))
     
-    op = options(warn = (-1))
-    retdata = data.frame()
+    #op = options(warn) 
+
+    retdata <- data.frame()
     for (state in states) {
         # get the data I want for that state
         mydata <- hdata[hdata$State==state, c(7, 2, colnum)]
         } else { 
             decr <- FALSE
             getrow <- num
-            #if (num > numrows) ret <- NA
         }
         if (is.numeric(num) && (num > numrows)) {
             ret <- NA
                        decreasing=decr
                       ),][getrow,2]
         }
-        retdata <- rbind(retdata, c(ret, state))
+        rd <- data.frame(hospital = ret, state = state)
+        retdata <- rbind(retdata, rd)
+        #print(sprintf("%s -> %s", state, ret))
     }
-    names(retdata) <- c("hospital", "state")
+    #names(retdata) <- c("hospital", "state")
     return(retdata)
-    options(op)
+    #options(op)
 }
 
 

coursera/week3/rankhospital.R

     } else if (num == "worst") {
         decr <- TRUE
     } else {
+        decr <- FALSE
         getrow = num
         if (num > numrows) {
             return(NA)