I have this code here.
library(plyr)
rankhospital <- function(state, illness, rank) {
outcome <- read.csv("data3/outcome.csv")
hA <- cbind(as.numeric(as.character(outcome[,11][outcome$State == state])),
as.character(outcome$Hospital.Name[outcome$State == state]))
hF <- cbind(as.numeric(as.character(outcome[,17][outcome$State == state])),
as.character(outcome$Hospital.Name[outcome$State == state]))
pN <- cbind(as.numeric(as.character(outcome[,23][outcome$State == state])),
as.character(outcome$Hospital.Name[outcome$State == state]))
condition <- ifelse(illness == "heart attack", list(hA), ifelse(illness == "heart failure", list(hF),
ifelse(illness == "pneumonia", list(pN), "not a valid input")))
outcomeData <- as.data.frame(condition)
rates <- outcomeData[,1]
hospitals <- outcomeData[,2]
outcomeData$rank <- ddply(outcomeData,.(hospitals),transform,Order =rank(rates,ties.method = "first"))
print(outcomeData$rank)
}
I can use the rank function , however I want to rank alphabetically by hospital first. I can't do this with the rank function. Every time I use a package to rank by an additional variable I get this error.
Error in head(outcomeData) : object 'outcomeData' not found
I've googled this issue and it seems that I have a problem related to the lexical scoping rules of R, however, I'm confused because i've used packages outside of functions fine, I don't understand why I'm getting this issue here.