How is it possible to set the column value to the last positive integer? Here is an example:
Here is a dataframe:
id <- c(1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2)
test <- c(5,6,-1,2,3,-1,-2,-3,5,-2,-1,1,1,2,-3,-3,2,3,5,4)
df1 <- data.frame(id,test)
Desired output:
id|test
1 |5
1 |6
1 |6
1 |2
1 |3
1 |3
1 |3
1 |3
1 |5
1 |5
2 |NA
2 |1
2 |1
2 |2
2 |2
2 |2
2 |2
2 |3
2 |5
2 |4