GL <[email protected]> [Mon, Jun 28, 2010 at 05:46:13PM CEST]:
>
> I'm guessing there's a more efficient way to do the following using the index
> features of R. Appreciate any thoughts....
1st thought: ifelse()
>
> for (i in 1:nrow(dbs1)){
> if(dbs1$Payor[i] %in% Payor.Group.Medicaid) dbs1$Payor.Group[i] =
> "Medicaid"
within(dbs1, Payor.Group <- ifelse(Payor %in% Payor.Group.Medicaid, "Medicaid",
ifelse( and so on ))
2nd thought: library(car); ?recode
3rd thought (untested and contrary to the spirit of R):
lst <- list("Medicare", "Commercial", "Workers.Comp", etc. );
codePayor <- function(lst) {
if (length(lst) == 0) ""
else ifelse(dbs1$Payor %in% eval(parse(paste("Payor.Group", lst[[1]],
sep="."))),
lst[[1]],
codePayor(lst[-1]))
}
dbs1$Payor.Group <- codePayor(lst)
--
Johannes Hüsing There is something fascinating about science.
One gets such wholesale returns of conjecture
mailto:[email protected] from such a trifling investment of fact.
http://derwisch.wikidot.com (Mark Twain, "Life on the Mississippi")
______________________________________________
[email protected] 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.