[R] error in submission

David Winsemius dwinsemius at comcast.net
Sat Jan 31 18:43:49 CET 2015


This is clearly a homework problem and probably one for an online Coursera course. If that guess is correct, then you should be using the facilities for help through the course website.

On Jan 31, 2015, at 2:11 AM, Wael Hammam Fouad wrote:

>  R x64 3.1.2 RStudio win8.1 64x error in submission
> assignment 3 best function
> *actually i have 2 code *
> *the first have good **output but error in submission :*
> *Selection: 1Error in best("BB", "heart attack") : Invalid stateCalled
> from: .rs.breakOnError(TRUE)*
> best <- function(state, outcome) {
>        outmeasures <- read.csv("outcome-of-care-measures.csv", colClasses
> = "character")
>        caremeasures <- subset(outmeasures,,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"))
>        names(caremeasures) <- c("Hospital.Name", "State", "Heart.Attack",
>                                 "Heart.Failure", "Pneumonia")
>        measuresstate <- subset(caremeasures[caremeasures$State == state ,
>                                             c("Hospital.Name", "State" ,
>                                               "Heart.Attack", "Heart.Failure",
>                                               "Pneumonia")])

>        if(!state %in% measuresstate$State) {
>                stop("Invalid state")
>        }
>        if(outcome == "heart attack") {
>                minHos <- measuresstate[, c("Hospital.Name",
> "Heart.Attack")]
>                minHos[, "Heart.Attack"] <-
> suppressWarnings(as.numeric(minHos[, "Heart.Attack"]))
>                minHosN <- na.omit(minHos)
>                minHospital <- minHosN[with(minHosN, order(Heart.Attack,
> Hospital.Name)), ]
>                return(minHospital[[1]][[1]])
>        }else if(outcome == "heart failure") {
>                minHos <- measuresstate[, c("Hospital.Name",
> "Heart.Failure")]
>                minHos[, "Heart.Failure"] <-
> suppressWarnings(as.numeric(minHos[, "Heart.Failure"]))
>                minHosN <- na.omit(minHos)
>                minHospital <- minHosN[with(minHosN, order(Heart.Failure,
> Hospital.Name)), ]
>                return(minHospital[[1]][[1]])
>        }else if(outcome == "pneumonia") {
>                minHos <- measuresstate[, c("Hospital.Name", "Pneumonia")]
>                minHos[, "Pneumonia"] <-
> suppressWarnings(as.numeric(minHos[, "Pneumonia"]))
>                minHosN <- na.omit(minHos)
>                minHospital <- minHosN[with(minHosN, order(Pneumonia,
> Hospital.Name)), ]
>                return(minHospital[[1]][[1]])
>        }else{
>                stop("Invalid outcome")
>        }
> }
> 
> 
> *the second have error* (best("BB", "heart attack")
> Error in minHospital[[1]][[1]] : subscript out of bounds)
> 
> *and it's looks like no check on state the is as follow :*

That phrase cannot be parsed by this native-speaker.

> best <- function(state, outcome) {
>        outmeasures <- read.csv("outcome-of-care-measures.csv",
> stringsAsFactors=FALSE, na.strings="Not Available")
>        if(!state %in% outmeasures$State |
>           !outcome %in%
> outmeasures$Hospital.30.Day.Death..Mortality..Rates.from.Heart.Attack |
>           !outcome %in%
> outmeasures$Hospital.30.Day.Death..Mortality..Rates.from.Heart.Failure |
>           !outcome %in%
> outmeasures$Hospital.30.Day.Death..Mortality..Rates.from.Pneumonia) {
>        caremeasures <- subset(outmeasures,,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"))
>        names(caremeasures) <- c("Hospital.Name", "State", "Heart.Attack",
>                                 "Heart.Failure", "Pneumonia")
>        measuresstate <- subset(caremeasures[caremeasures$State == state ,
>                                c("Hospital.Name", "State" ,
> "Heart.Attack",
>                                  "Heart.Failure", "Pneumonia")])
>        if(outcome == "heart attack") {
>                minHos <- measuresstate[, c("Hospital.Name",
> "Heart.Attack")]
>                minHos[, "Heart.Attack"] <-
> suppressWarnings(as.numeric(minHos[, "Heart.Attack"]))
>                minHosN <- na.omit(minHos)
>                minHospital <- minHosN[with(minHosN, order(Heart.Attack,
> Hospital.Name)), ]
>                return(minHospital[[1]][[1]])
>        }else if(outcome == "heart failure") {
>                minHos <- measuresstate[, c("Hospital.Name",
> "Heart.Failure")]
>                minHos[, "Heart.Failure"] <-
> suppressWarnings(as.numeric(minHos[, "Heart.Failure"]))
>                minHosN <- na.omit(minHos)
>                minHospital <- minHosN[with(minHosN, order(Heart.Failure,
> Hospital.Name)), ]
>                return(minHospital[[1]][[1]])
>        }else if(outcome == "pneumonia") {
>                minHos <- measuresstate[, c("Hospital.Name", "Pneumonia")]
>                minHos[, "Pneumonia"] <-
> suppressWarnings(as.numeric(minHos[, "Pneumonia"]))
>                minHosN <- na.omit(minHos)
>                minHospital <- minHosN[with(minHosN, order(Pneumonia,
> Hospital.Name)), ]
>                return(minHospital[[1]][[1]])
>        }else{
>                stop("Invalid outcome")
>        }
>        }
>        stop("Invalid State")
> }
> 
> what is the problem I'm really confused and not understand what is the
> problem i need to put my hand on the problem
> Sorry for inconvenience
> 
> 	[[alternative HTML version deleted]]

This is a non-HTML zone of discourse.

> 
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius
Alameda, CA, USA



More information about the R-help mailing list