Dear R-helper,

I am working on a very large data frame and I am trying to add a new column
and write in it with certain conditions. I have try to use this code with
the data frame p :

ID = 0

p[,"newColumn"]<-
    ifelse (p$flagFoehn3_durr == 1,
        ifelse(p$Guetsch == 0,
            ID <<- ID ++
        ,
            ID
        )
    ,
    0
    )

What I am trying to do is to increment the ID when p$Guetsch == 0 and to
put this result in the column. The problem is that ID does not increment
itself.

An other way is to use a loop for like this example :

ID = 0
for (s in 1:(nrow(z))){

    z[s,"newColumn"]<-
        if (z$flagFoehn3_durr[s] == 1){
            if(z$flagFoehn3_durr[s-1] == 0){
                ID <<-ID+1
            }else{
                ID
            }
        }else{
        0
        }
}

This work perfectly, but the problem is that it will take me more than a
month to run it.

Is there a way to increment with the first code I used or a way of running
the second code faster (I have more than 1 million rows)

Thanks!

Cheers,

Damien

	[[alternative HTML version deleted]]


