Suppose I have a dataframe column (or a vector) with a sequence of numbers ranging from 1 to 4 (for example). Suppose also that a second column or vector must be constructed in the following way:
The new column has a 3, say, in a particular row because that is the new number the first vector changes to after having been 4, say. So, for example:
Col1: [4, 4, 4, 3, 3, 1, 2, 2, 2]
would result in
Col2: [3, 3, 3, 1, 1, 2, NaN, NaN, NaN]
Not that the last three items are NaN because there is no information about what comes after 2.
My question is simply, what code in Julia finds Col2 in an efficient t way?
Great solution! It assumes that values wonβt be repeated after a streak has ended (e.g., [4, 4, 4, 3, 3, 1, 2, 2, 2, 1, 2, 3, 4]), but that should be safe to do, depending on the context.