[R] Basic question - more efficient method than loop?

Allan Engelhardt allane at cybaea.com
Mon Jun 28 18:18:25 CEST 2010

On 28/06/10 16:46, GL wrote:
> 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"

Try something like

dbs1$Payor.Group[dbs1$Payor %in% Payor.Group.Medicaid]<- "Medicaid"

to get started.

Hope this helps.


>     [...]

More information about the R-help mailing list