0

How would I go about subtracting Read in line 1 from Read in line 5 and make that the value of Read in line 1. Then repeat so subtract Read in line 2 from line 6 and so on? Then adding up each group of 4 lines (the same time stamp) and making one line with that time stamp that is the sum of all four lines?

                  Time Meter     Read
1   2017-03-20 14:15:00     1 22582640
2   2017-03-20 14:15:00     2   571893
3   2017-03-20 14:15:00     3 45906886
4   2017-03-20 14:15:00     4  1890581
5   2017-03-20 14:20:00     1 22582640
6   2017-03-20 14:20:00     2   571893
7   2017-03-20 14:20:00     3 45906993
8   2017-03-20 14:20:00     4  1890581
9   2017-03-20 14:25:00     1 22582640
10  2017-03-20 14:25:00     2   571893
11  2017-03-20 14:25:00     3 45907206
12  2017-03-20 14:25:00     4  1890581
13  2017-03-20 14:30:00     1 22582640
14  2017-03-20 14:30:00     2   571893
15  2017-03-20 14:30:00     3 45907206
16  2017-03-20 14:30:00     4  1890581

dput of data is:

structure(list(Time = structure(c(1490037300, 1490037300, 1490037300, 
1490037300, 1490037600, 1490037600, 1490037600, 1490037600, 1490037900, 
1490037900, 1490037900, 1490037900, 1490038200, 1490038200, 1490038200, 
1490038200), class = c("POSIXct", "POSIXt"), tzone = ""), Meter = c(1, 
2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4), Read = c(22582640L, 
571893L, 45906886L, 1890581L, 22582640L, 571893L, 45906993L, 
1890581L, 22582640L, 571893L, 45907206L, 1890581L, 22582640L, 
571893L, 45907206L, 1890581L)), .Names = c("Time", "Meter", "Read"
), row.names = c(NA, 16L), class = "data.frame")

The result that I would want is this:

1   2017-03-20 14:15:00     1 107
2   2017-03-20 14:20:00     1 213

and so on.

I do not need to reference the Meter column if that makes it less complex. I could remove that column and just do some sort of offset as the formatting will always be the 4 entries together. I got the data formatted this far but I don't know where to begin to do what I am looking for as it means wiping out three lines and I'm not sure how that affects the offset for later calculations. I thought about adding a new column with the calculation but still can't figure out how to roll the sum up into one line.

jogo
  • 12,306
  • 11
  • 34
  • 41

0 Answers0