Extend example to introduce associations in vignette
Closed this issue · 0 comments
bjcairns commented
As suggested by @Feakster, data could be reshaped to make it easier to produce synthetic data which differs by category, e.g. solving the limitation of the current vignette example.
This code seems to work to convert between appropriate wide and long formats (some rearrangement of variables being required at the end to recover iris
):
library(magrittr)
irisidd <- iris %>% dplyr::mutate(id = rep(1:50,3))
irisidd_wide <- tidyr::pivot_wider(
irisidd,
id_cols = id,
names_from = Species,
values_from = c(Sepal.Length, Sepal.Width, Petal.Length, Petal.Width)
)
irisidd_long <- tidyr::pivot_longer(
irisidd_wide,
-id,
names_to = c(".value", "Species"),
names_sep = "_"
)
There are no doubt data.table and base ways to do this also. 😄