I want to retrieve the value from one column, based on the values in another column. I have included an example which should help explain.
For this example, if we say that we want to return the value in index where the next value in number is less than or equal to the current number-10, we would get the column ind_return:
index number ind_return
1 A 100 C
2 B 105 C
3 C 84 NA
4 D 90 G
5 E 120 F
6 F 110 G
7 G 75 NA
df <- data.frame(index = c("A", "B", "C", "D", "E", "F", "G"),
number = c(100, 105, 84, 90, 120, 110, 75))
The question is, how can we get ind_return?