I am trying to refer to the previous row in the same column inside a calculation for said column. However this always leads to an 'Unknown or uninitialised column' warning message and a lot of NA's.
df$A c( -1, -2, -1, 1, 2, 4 )
df$B <- ifelse(df$A <= 0 , 0, ifelse(lag(df$B,1) == 0,1,2))
This gives me the previously mentioned error. How can i refer to previous rows in the same column when calculating said column?
Aucun commentaire:
Enregistrer un commentaire