lundi 11 juin 2018

How can I get ifelse to perform a calculation based on the next row?

I'm trying to run what would normally (I suppose) be an iteration down a data-frame, however I've started using ifelse.

I'd like to have the ifelse function perform it's feature based on a previous rows value and then input the result of the logic into the next row. So far, I've got the below;

a.1$Trl<- for (i in nrow(a.1)){
            a.1Trl[i+1,] <- ifelse(as.numeric(a.1$K)>=0.8, (a.1$O[i+1,]-a.1$C[i+1,])*s,  0)
                }

I'm not sure if the iteration with a nested logical function is going to work however have come to a dead end. Any ideas?

Aucun commentaire:

Enregistrer un commentaire