I have a dataset where I need to change any values that are 0, but have had a non-zero value in the past 48 hours to a specific string. I'm guessing I might need to convert all but the first column from dbl to chr before doing this?
Time colA colB colC colD
<dttm> <dbl> <dbl> <dbl> <dbl>
1 2021-11-21 10:00:00 8 0 9 176
2 2021-11-11 11:00:00 21 0 22 416
3 2021-11-21 11:00:00 19 0 20 373
4 2021-11-11 12:00:00 40 13 28 566
5 2021-11-21 12:00:00 26 0 27 527
6 2021-11-11 13:00:00 50 20 32 651
7 2021-11-11 10:00:00 11 0 12 216
8 2021-11-21 13:00:00 30 0 31 617
9 2021-11-11 14:00:00 51 0 32 675
10 2021-11-21 14:00:00 31 0 32 644
Apologies that the data isn't sorted by time already, working on fixing that. For example, here's the output that I'd like to get to:
Time colA colB colC colD
<dttm> <dbl> <dbl> <dbl> <dbl>
1 2021-11-21 10:00:00 8 0 9 176
2 2021-11-11 11:00:00 21 0 22 416
3 2021-11-21 11:00:00 19 0 20 373
4 2021-11-11 12:00:00 40 13 28 566
5 2021-11-21 12:00:00 26 0 27 527
6 2021-11-11 13:00:00 50 20 32 651
7 2021-11-11 10:00:00 11 0 12 216
8 2021-11-21 13:00:00 30 0 31 617
9 2021-11-11 14:00:00 51 STRING1 32 675
10 2021-11-21 14:00:00 31 0 32 644
Since colB has a value of 0 at 2021-11-11 14:00:00, but atleast 1 of the previous values in the 48 hours before that != 0, it gets changed to "STRING1"
Apologies if this is confusing, I'm trying to automate something I typically do manually in Excel. Thanks in advance