[R] Sum every n (4) observations by group

Miluji Sb m||uj|@b @end|ng |rom gm@||@com
Sun Dec 19 19:31:34 CET 2021


Dear all,

I have a dataset (below) by ID and time sequence. I would like to sum every
four observations by ID.

I am confused how to combine the two conditions. Any help will be highly
appreciated. Thank you!

Best.

Milu

## Dataset
structure(list(ID = c("A", "A", "A", "A", "A", "A", "A", "A",
"B", "B", "B", "B", "B", "B", "B", "B", "C", "C", "C", "C", "C",
"C", "C", "C"), Date = c(4140L, 4141L, 4142L, 4143L, 4144L, 4145L,
4146L, 4147L, 4140L, 4141L, 4142L, 4143L, 4144L, 4145L, 4146L,
4147L, 4140L, 4141L, 4142L, 4143L, 4144L, 4145L, 4146L, 4147L
), Value = c(0.000207232, 0.000240141, 0.000271414, 0.000258384,
0.00024364, 0.00027148, 0.000280585, 0.000289691, 0.000298797,
0.000307903, 0.000317008, 0.000326114, 0.00033522, 0.000344326,
0.000353431, 0.000362537, 0.000371643, 0.000380749, 0.000389854,
0.00039896, 0.000408066, 0.000417172, 0.000426277, 0.000435383
)), class = "data.frame", row.names = c(NA, -24L))

	[[alternative HTML version deleted]]



More information about the R-help mailing list