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
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
ifelse(df$Rainfall > 0, 1, 0)