Hi

I submited the rankhospital project. All parts were correct except part 2.
I checked the outcome and it looks correct. I am afraid I am
misunderstanding the requirement. Please let me know why the outcome is not
correct.


*THE OUTCOMEMy test*
> source("rankhospital.R")
> d<-rankhospital("WA","heart attack",7)
> d
[1] "EVERGREEN HOSPITAL MEDICAL CENTER"


*Note:*
  Hospital Name State Heart Attack  VIRGINIA MASON MEDICAL CENTER WA
10.2  PEACHEALTH
ST JOHN MEDICAL CENTER WA 10.6  SWEDISH MEDICAL CENTER/CHERRY HILL WA
10.8  CENTRAL
WASHINGTON HOSPITAL WA 10.8  PEACEHEALTH ST JOSEPH MEDICAL CENTER WA
11  UNIVERSITY
OF WASHINGTON MEDICAL CTR WA 11  PROVIDENCE SACRED HEART MEDICAL CENTER WA
11  DEACONESS HOSPITAL WA 11.1  YAKIMA VALLEY MEMORIAL HOSPITAL WA
11.1  PROVIDENCE
HOLY FAMILY HOSPITAL WA 11.4  EVERGREEN HOSPITAL MEDICAL CENTER WA 11.5
"EVERGREEN HOSPITAL MEDICAL CENTER" is actually the 7th ranking hospital in
WA with 11.5 rate for heart attack and the outcome is of type character
vector


*The result*
> submit()
[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]? 5
Running test:
rankhospital("WA", "heart attack", 7)
Result:  Incorrect!



*THE CODE*
#  rankhospital.R
rankhospital<-function(state,outcome,num){

#----read file
alldata<-read.csv("outcome-of-care-measures.csv",colClasses="character")
allnames<-names(alldata)

#----Verifty parameters
modoutcome<-paste(".",gsub(" ",".",outcome),sep="")
matchoutcome<-agrep(modoutcome,allnames)
allstates<-alldata$State
matchstate<-grep(state,allstates)
if (length(matchoutcome)==0) stop("invalid outcome")
if (length(matchstate)==0) stop("invalid state")

#----Construct name
lowesttext<-"Lower.Mortality.Estimate...Hospital.30.Day.Death..Mortality..Rates.from."
lowestnames<-(grep(lowesttext,allnames))
selectedoutcomeindex<-which(matchoutcome %in% lowestnames)
selectedoutcome<-allnames[matchoutcome[selectedoutcomeindex]]

#----Get all data for the state
ssdata<-subset(alldata,State %in% c(state),
select=c("Hospital.Name","State",selectedoutcome))
#ssdata<-cbind(ssdata,Rank="")
suppressWarnings(ssdata[,selectedoutcome]<-as.numeric(ssdata[,selectedoutcome]))
ccssdata<-complete.cases(ssdata)
nonassdata<-ssdata[ccssdata,]

colnames(nonassdata)[3]<-"Rate"

surate<-sort(unique(nonassdata[,3]))
numrate=length(surate)+1 # value serves as a flag

#---- Get the num selectedoutcome value
if(num=="worst") {
    numrate<-max(surate)
}
else if (num=="best") {
    numrate<-min(surate)
}
else if(num<= length(surate)) {
    numrate<-surate[num]
}

numssdata<-subset(nonassdata[order(nonassdata$Hospital.Name),],Rate==numrate)

if (numrate<=length(surate)) {
    lowestrankinghospitals<-numssdata$Hospital.Name
}
else lowestrankinghospitals="NA"
#----
#print(surate)
lowestrankinghospitals
}

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
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.

Reply via email to