R how to obtain the mean of previous values depending on a second column with data in long format
I prepared a reproducible example with an example of dataset here: patient <- c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2) month <- rep (1:10, 2) fev1 <- c(58, NA, NA, NA, 57, NA, NA, NA, NA, 60, NA, NA, NA, NA, 32,… Read More R how to obtain the mean of previous values depending on a second column with data in long format