Skip to content

Instantly share code, notes, and snippets.

@szimmer
Last active October 28, 2019 11:16
Show Gist options
  • Save szimmer/83a4fd1073385fde19a67a5413d27bed to your computer and use it in GitHub Desktop.
Save szimmer/83a4fd1073385fde19a67a5413d27bed to your computer and use it in GitHub Desktop.
Making Multiple Amortization Tables
source("https://gist.githubusercontent.com/schaunwheeler/6380637/raw/02d345971e3513f69b30fe2ba262578ac3871fe2/amortize.r")
library(tidyverse)
set.seed(1028)
testdata <- tibble(principal=rnorm(20, 200000, 10000),
interest=runif(20, .01, .1),
months=rbinom(20, 360, .5))
# This will not work because function is not vectorized
# data_withtabs <- testdata %>%
# mutate(AmTable=amortize(p_input=principal, i_input=interest, n_months=months))
am_tables <- pmap(list(testdata$principal, testdata$interest, testdata$months),
function(x, y, z) amortize(p_input=x, i_input=y, n_months = z))
glimpse(am_tables)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment