[R] Basic question - more efficient method than loop?
GL
pflugg at shands.ufl.edu
Mon Jun 28 17:46:13 CEST 2010
I'm guessing there's a more efficient way to do the following using the index
features of R. Appreciate any thoughts....
for (i in 1:nrow(dbs1)){
if(dbs1$Payor[i] %in% Payor.Group.Medicaid) dbs1$Payor.Group[i] =
"Medicaid"
if(dbs1$Payor[i] %in% Payor.Group.Medicare) dbs1$Payor.Group[i] =
"Medicare"
if(dbs1$Payor[i] %in% Payor.Group.Commercial) dbs1$Payor.Group[i] =
"Commercial"
if(dbs1$Payor[i] %in% Payor.Group.Workers.Comp) dbs1$Payor.Group[i] =
"Workers Comp"
if(dbs1$Payor[i] %in% Payor.Group.Self.Pay) dbs1$Payor.Group[i] = "Self
Pay"
if(dbs1$Adm.Source[i] %in% Adm.Source.Group.Newborn)
dbs1$Adm.Source.Group[i] = "Newborn"
if(dbs1$Adm.Source[i] %in% Adm.Source.Group.ED) dbs1$Adm.Source.Group[i]
= "ED"
if(dbs1$Adm.Source[i] %in% Adm.Source.Group.Routine)
dbs1$Adm.Source.Group[i] = "Routine"
if(dbs1$Adm.Source[i] %in% Adm.Source.Group.Transfer)
dbs1$Adm.Source.Group[i] = "Transfer"
}
--
View this message in context: http://r.789695.n4.nabble.com/Basic-question-more-efficient-method-than-loop-tp2271096p2271096.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list