Why split the data.frame?
something like this would help?
df <- data.frame('hospital' = LETTERS[1:6],
'state' = rep(c('state1', 'state2', 'state3'),2),
'mr' = c(1:6))
df
hospital state mr
1 A state1 1
2 B state2 2
3 C state3 3
4 D state1 4
5 E state2 5
6 F state3 6
df2 <- df[with(df, order(-mr, state)), ]
df2[!duplicated(df2$state), ]
hospital state mr
6 F state3 6
5 E state2 5
4 D state1 4
You could do it with your approach but maintaining the list with all initial complete entries. But why?
ds <- split(df, df$state)
rate <- list()
for (i in 1:length(ds)){
## remove all rows with NA
rate[[i]] <- ds[[i]][complete.cases(ds[[i]][ ,3]), ]
##sort by mortality and remove
## conflict by hospital name
rate[[i]] <- rate[[i]][order(- rate[[i]][, 3], rate[[i]][ ,1]), ]
}
rate
[[1]]
hospital state mr
4 D state1 4
1 A state1 1
[[2]]
hospital state mr
5 E state2 5
2 B state2 2
[[3]]
hospital state mr
6 F state3 6
3 C state3 3