Closed ghost closed 5 years ago
Thank you for you for your effort in not only reporting the bug, but also looking for its cause. Much appreciated! I can confirm reproduction of the bug and will provide a fix in the upcoming release.
Thank you for the great package, makes my life a lot easier! I am glad I could help!
There seems to be an issue with thicken on variables with at least two missing values. Here is a little reprex to show the problem:
Created on 2019-04-14 by the reprex package (v0.2.1)
Now, if we call thicken on this data, then the NA values in the new column will be shifted by one, two, etc. for the second, third, etc. missing values of the original column:
Created on 2019-04-14 by the reprex package (v0.2.1)
I think the issue comes from the following line of the add_na_to_thicken function: https://github.com/EdwinTh/padr/blob/30654549062815aa264e58e2daa16541d9246c5e/R/thicken.R#L238
For example, if we take the second missing value, then the indices of the non-missing values after the second missing value will be shifted by at least two (in the example above, 2000-02-05 will have index 4 in the thickened vector, while the second missing value has index 5), hence we have two subtract 1.5 from the index of the second missing value, not just 0.5. Similary for the third, fourth, etc. missing value, we have to subtract 2.5, 3.5, etc. from the original index of the missing value.
This suggests that the following quick and dirty modification might work (and indeed, it did work for me), however this might not be the best solution.