Description Usage Arguments Examples
View source: R/roll_previous.R
Wrapper for zoo::rollapply for applying a function to rolling windows and getting the result of the previous window. Appends NAs at start only.
1 | roll_previous(v, width = 2, FUN = mean)
|
v |
Vector. |
width |
Number of previous row to apply function to. |
FUN |
Function to apply. Must be compatible with rollapply. |
1 2 3 4 5 6 7 8 9 | # Attach package
library(LRO.utilities)
# Create dataframe
df <- data.frame('round' = c(1,2,3,4,5,6,7,8,9,10),
'score' = c(5,3,4,7,6,5,2,7,8,6))
# For each row we find the mean score of the previous 2 rounds
df$mean_prev_score = roll_previous(df$score, width = 2, FUN = mean)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.