Applying IF statement to entire column in R

前端 未结 1 885
感动是毒
感动是毒 2021-01-17 03:11

I am trying to find a quick way to apply an IF statement to an entire column in R to create a new column of 1\'s and 0\'s depending on the statement. Specifically I want to

相关标签:
1条回答
  • 2021-01-17 03:25

    We can wrap with + to the logical condition to coerce to binary vector. It will be fast.

    +(df$Rainfall >0)
    

    Or if we are using ifelse, there is no need to loop, as it is vectorized

     ifelse(df$Rainfall > 0, 1, 0)
    
    0 讨论(0)
提交回复
热议问题