A (small example) of my data is structured as follows:
Individ <- data.frame(Participant = c("Bill", "Bill", "Bill", "Bill", "Bill", "Bill", "Jane", "Jane", "Jane", "Jane",
"Jane", "Jane", "Jane", "Jane", "Jane", "Jane", "Jane", "Jane", "Bill", "Bill", "Bill", "Bill", "Bill", "Bill"),
Time = c(1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6),
Condition = c("Placebo", "Placebo", "Placebo", "Placebo", "Placebo", "Placebo", "Expr", "Expr", "Expr", "Expr", "Expr", "Expr",
"Placebo", "Placebo", "Placebo", "Placebo", "Placebo", "Placebo", "Expr", "Expr", "Expr", "Expr", "Expr", "Expr"),
Location = c("Home", "Home", "Home", "Home", "Home", "Home", "Home", "Home", "Home", "Home", "Home", "Home", "Home", "Home", "Home", "Home", "Home", "Home",
"Away", "Away", "Away", "Away", "Away", "Away"),
Power = c(400, 250, 180, 500, 300, 450, 600, 512, 300, 500, 450, 200, 402, 210, 130, 520, 310, 451, 608, 582, 390, 570, 456, 205))
I wish to calculating a rolling three second average of Power
over Time
for each Participant
at both Condition
and Location
.
My research design is a repeated measures cross-over, evident that Jane has power recorded at Home under both treatment conditions (Placebo v Exper). My dataset is 4 million rows in length, how can I please quickly and easily calculate this moving average?
This question: Constructing moving average over a categorical variable in R is similar as is this: Rolling mean (moving average) by group/id with dplyr but I am wanting to average over a three second period and more than one grouping variable.