Learn R Programming

DataCombine (version 0.1.12)

PercChange: Calculate the percentage change from a specified lag, including withing group

Description

Calculate the percentage change from a specified lag, including withing group

Usage

PercChange(data, Var, GroupVar = NULL, NewVar = NULL, slideBy = -1,
  type = "percent")

Arguments

Value

  • a data frame

Details

Finds the percentage or proportion change for over a given time period either within groups of data or the whole data frame. Important: the data must be in time order and, if groups are used, group-time order.

Examples

Run this code
# Create fake data frame
A <- c(1, 1, 1, 1, 1, 2, 2, 2, 2, 2)
B <- c(1:10)
Data <- data.frame(A, B)

# Find percentage change from two periods before
Out <- PercChange(Data, Var = 'B', GroupVar = NULL,
         type = 'proportion', NewVar = 'PercentChange', slideBy = -2)

Out

Run the code above in your browser using DataLab