inst/doc/motivation.R

## ---- include = FALSE---------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

## ----setup--------------------------------------------------------------------
library(transx)

## ----problem, message=FALSE---------------------------------------------------
library(dplyr)
options(tibble.print_min = 3)

## -----------------------------------------------------------------------------
econ <- ggplot2::economics
econ

## ----exist-already, error=TRUE------------------------------------------------
mutate(econ, pop_lag = stats::lag(as.ts(pop)))

## ----dplyr-lag----------------------------------------------------------------
mutate(econ, pop_lag = dplyr::lag(pop))

## ----example-diff, error=TRUE-------------------------------------------------
mutate(econ, pop_diff = base::diff(pop))

## ----new-fun------------------------------------------------------------------
diffx <- function(x, ...) x - dplyr::lag(x, ... )

mutate(econ, pop_diff = diffx(pop))

Try the transx package in your browser

Any scripts or data that you put into this service are public.

transx documentation built on Nov. 27, 2020, 5:08 p.m.