lundi 4 janvier 2021

If condition is met, go 100 rows above and select the value in R

I am trying to do in R the following: In my dataset (md2), if L_ID=1, go 100 rows above and create a new dataframe with the variable Hway. I use the following command:

spc <- data.frame(md$Hdwy[c(md2$L_ID[-100], 0) == 1])

It seems to work, however when I checked I noticed that it selects the value 1 row above instead of 100, any ideas?

Aucun commentaire:

Enregistrer un commentaire