I have a dataframe with a column like this:
He is an example of the dataframe (the real one has multiple columns however for this I will just post the important column):
structure(list(frame = c(0L, 0L, 0L, 0L, 473047L, 0L, 473049L,0L, 0L, 473051L, 0L, 0L, 473052L, 0L, 473055L)), row.names = c(NA, -15L), class = "data.frame")
The frame column denotes the frame number. The 0s in the column belong to the same frame as the large number that follows. Hence I want to change the first four 0s to be 473047, then the next singular 0 to be 473049, then the following two 0s to be 473051, and so on for my analysis.
Does anybody have an tips on how to do this in base R or using the tidyverse? I thought maybe a for loop/if statement combo could work through some kind of indexing procedure i.e.
for the length of the frame column
if frame > 0
count back up the column and replace the preceding 0s with that number
However I cannot think of a possible solution beyond this pseudo-code. Any help would be most appreciated!