Looked over several posts on this topic, but still couldn't figure out. Thought I'd just ask:
I wrote a for-loop:
for (i in 0:5) {
est16_y2016$pov50_[i] <- est16_y2016$pop[i]*est16_y2016$ITPR_0.5
}
to achieve the same results as the following code:
est16_y2016$pov50_0 <- est16_y2016$pop0 * est16_y2016$ITPR_0.5
est16_y2016$pov50_1 <- est16_y2016$pop1 * est16_y2016$ITPR_0.5
est16_y2016$pov50_2 <- est16_y2016$pop2 * est16_y2016$ITPR_0.5
est16_y2016$pov50_3 <- est16_y2016$pop3 * est16_y2016$ITPR_0.5
est16_y2016$pov50_4 <- est16_y2016$pop4 * est16_y2016$ITPR_0.5
est16_y2016$pov50_5 <- est16_y2016$pop5 * est16_y2016$ITPR_0.5
But the loop doesn't work. No error message, no new variables generated either. Help! Thanks.
paste0('est16_y2016$pov50_',i)for (i in 0:5) est16_y2016[,paste0('pov50_',i)] <- est16_y2016[,paste0('pop',i)]*est16_y2016$ITPR_0.5 }