0

I have a df like this:

Line Sensor Day Time Measurement
1 A 1 10:00:00 56
2 A 1 11:00:00 42
3 A 1 12:00:00 87
4 A 1 12:20:00 12
5 A 1 12:50:00 44

I would like to create some rows. Considering that measurements should be taken every 10 minutes I would like to add a non-constant number of rows (i.e there should be 6 between line 1 and 2; two rows between line 3 and 4; 3 rows between line 4 and five) in order to get something similar to this:

Line Sensor Day Time Measurement
1 A 1 10:00:00 56
2 A 1 10:10:00 54
3 A 1 10:20:00 35
4 A 1 10:30:00 11
5 A 1 10:40:00 45
6 A 1 10:50:00 56
7 A 1 11:00:00 90
... ... ... ... ... ... ...
13 A 1 12:00:00 87
14 A 1 12:10:00 97
15 A 1 12:20:00 42
16 A 1 12:30:00 67
4 A 1 12:40:00 76
5 A 1 12:50:00 11

Any suggestion?

  • 1
    Perhaps you could use the tidyr function `complete()`, e.g. https://stackoverflow.com/a/56192036/12957340 ? – jared_mamrot Dec 06 '22 at 09:50
  • 1
    You're going to have to explain the logic. How are the missing values for `Measurement` derived? Why does the value for Sensor A Day 1 11:00:00 = 42 in the first data frame, but = 90 in the second? – neilfws Dec 06 '22 at 09:51
  • @neilfws in the example the `Measurement` values were random. I was thinking to measure the distance between the original rows(i.e suppose at time 10:00:00 `Measurement` = 80 and at `Time` 10:30:00 `Measurement` = 50), take the difference in `Measurement` at the two timestamps, divide it by the number of rows to be added so I'll have something like `time`: 10:10:00 `Measurement` = 70; `Time` 10:20:00 `Measurement` = 60 ecc. – Bartholomew Dec 06 '22 at 10:35

0 Answers0