How can I achieve same results without loop? It's equivalent of scan function in reactiveX but with custom logic (http://reactivex.io/rxjs/img/scan.png)
for (i in 2:nrow(x)) {
x$running_number[i] <-
ifelse(abs(x$running_number[(i - 1)] - x$numbers[i]) > max_diff,
x$numbers[i],
x$running_number[(i - 1)])
}
EDIT:
Not sure I asked correctly after your reply. Take a look at this dataframe
x <- data.frame(
c(1000, 1010, 1020, 1030, 1100, 1120, 1140, 1150, 1200),
c(1000, 1000, 1000, 1000, 1100, 1100, 1100, 1100, 1200)
)
colnames(x) <- c('input_v', 'output_v')
Given x$input_v need to get x$output_v
I can express condition like :
x$output_v <-
ifelse(
abs(x$input_v - somehow_get_me_last_assigned_x_output_v) > 90,
x$input_v,
somehow_get_me_last_assigned_x_output_v
)