Skip to content

Instantly share code, notes, and snippets.

@mxblsdl
Created July 30, 2020 23:15
Show Gist options
  • Save mxblsdl/e0f7d0023b5be6af9226eeb5c83dbcd9 to your computer and use it in GitHub Desktop.
Save mxblsdl/e0f7d0023b5be6af9226eeb5c83dbcd9 to your computer and use it in GitHub Desktop.
# add fake columns
cols_add <- as.character(2020:2039)
DT[, (cols_add) := 0]
for (col in cols_add) {
set(DT, i = 1L, j = col, value = state[1, total] * abs(rnorm(1, mean = 10)) + state[1, total])
set(DT, i = 2L, j = col, value = state[2, total] * abs(rnorm(1)) + state[2, total])
set(DT, i = 3L, j = col, value = state[3, total] * abs(rnorm(1)) + state[3, total])
set(DT, i = 4L, j = col, value = state[4, total] * abs(rnorm(1, mean = 10)) + state[4, total])
}
DT <-
DT %>%
tidyr::pivot_longer(cols = as.character(2020:2039))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment