approx_fun_constant: approx_fun_constant

View source: R/pipeline-helpers.R

approx_fun_constantR Documentation

approx_fun_constant

Description

approx (interpolation) for use in a dplyr pipeline.

Usage

approx_fun_constant(year, value, rule = 1)

Arguments

year

Numeric year, in a melted tibble or data frame

value

Numeric value to interpolate

rule

Rule to use; see approx and details

Details

This is a slight change to approx_fun that can be used if there is only one value, not two to interpolate between.

This function will apply the one value you do have to all other years in a grouping.

Value

Interpolated values.

Examples

df <- data.frame(year = 1:5, value = c(1, 2, NA, 4, 5))
approx_fun_constant(df$year, df$value, rule = 2)

JGCRI/gcamdata documentation built on March 21, 2023, 2:19 a.m.