Created
January 9, 2021 10:11
-
-
Save MilesMcBain/e0da1a1a1f1a6cbc3e9b7364bc9b33fe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(tidyverse) | |
| first_year <- tibble(year = 2010, z = 1, x = 2, y = 3) | |
| all_years <- first_year %>% | |
| bind_rows(tibble(year = 2011:2015)) | |
| all_years %>% | |
| summarise( | |
| year = year, | |
| accumulate( | |
| .init = tibble( | |
| x = first(all_years$x), | |
| y = first(all_years$y), | |
| z = first(all_years$z) | |
| ), | |
| .x = seq(length(z) - 1), # because we're supplying 1 row in init - tripped me up | |
| .f = function(inputs, x_ignored) { | |
| tibble( | |
| z = 0.5 * inputs$x, | |
| x = 0.5 * z + 0.5 * inputs$y, | |
| y = 0.25 * inputs$x | |
| ) | |
| } | |
| ) %>% | |
| bind_rows() | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment