Count <- c(1:10)
Give <- c(0,0,5,0,0,5,0,5,0,5)
X <- c(rep(0,10))
Y <- c(rep(0,10))
Z <- c(rep(0,10))
X_Target <- 5
Y_Target <- 10
Z_Target <- 5

Basically I have 3 vectors (X,Y,Z) and a target for each one of them. I want to have a new calculation for X,Y and Z that based on the vector Give. Once the number on Give is bigger than 0 then it's need to be added to Vector X until it equel to X_Target. Then - the calcultion need to move to the next vector (Y) and do the same, and then to next vector...

^{Created on 2020-12-08 by the reprex package (v0.3.0)}

I'm not sure how to generalize to arbitrary columns. The easiest would be with a for loop, something like that (with probably quite a bit of thinking required for correct initialization etc):

I don't see how to easily use *apply() or map_*() since the result of each column depends on the previous columns, that means you would need to expand some big combination vector to get the equivalent of sum_of_previous_targets .