roll_previous: Apply rolling functions to previous rows

Description Usage Arguments Examples

View source: R/roll_previous.R

Description

Wrapper for zoo::rollapply for applying a function to rolling windows and getting the result of the previous window. Appends NAs at start only.

Usage

1
roll_previous(v, width = 2, FUN = mean)

Arguments

v

Vector.

width

Number of previous row to apply function to.

FUN

Function to apply. Must be compatible with rollapply.

Examples

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)

LudvigOlsen/LRO.utilities documentation built on May 27, 2018, 4:21 p.m.