[R] Not sure if I have the requirement right.

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Sun Jan 26 09:03:39 CET 2014


You are confused. This is not the correct email to submit your project to. This is the R-help mailing list, and you desperately need to read the posting guide mentioned at the end of this email before you send anything else to this email address.
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.

"F. Keshavarz" <fkeshca at gmail.com> wrote:
>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 at 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.




More information about the R-help mailing list