Skip to content
Prev 388118 / 398502 Next

if statement and for loop question

Hello,

You don't need a loop, the R way is a vectorized solution and it's also 
clearer.
Create a logical index (note only one &) and assign b, c, d where it's TRUE.


i <- try$a != "Positive" & try$a != "VUS"
try <- within(try, {
   b[i] <- ''
   c[i] <- ''
   d[i] <- ''
})


Hope this helps,

Rui Barradas

?s 17:28 de 30/05/21, Kai Yang via R-help escreveu: