# Data to be extended
d <- SSBtoolsData("barcelona2025")[c(3, 6, 12, 18), -5]
rownames(d) <- NULL
d$year <- 2025:2026
d$month <- c("January", rep("August", 3))
d
# varGroups as a named list
varGroups <- list(geo = c("country", "city"),
age = "age",
sex = "sex",
time = c("month", "year"))
a0 <- Extend0(d, varGroups = varGroups)
dim(a0) # all combinations, 48 rows
a1 <- Extend0_with_n_rnd_groups(d, varGroups = varGroups, non_rnd = c("time", "geo"))
a1
dim(unique(a1[c("month", "year", "country", "city")])) # all combinations of time and geo
unique(a1[c("sex", "month", "year")]) # not all combinations
a2 <- Extend0_with_n_rnd_groups(d, varGroups = varGroups, non_rnd = c("sex", "time", "geo"))
dim(a2)
# all combinations of selected variables
dim(unique(a2[c("sex", "month", "year", "country", "city")]))
# not all combinations of selected variables
dim(unique(a2[c("age", "month", "year", "country", "city")]))
# effect of rnd_rep
for (rnd_rep in c(1, 2, 3, 5, 10, 50))
print(dim(Extend0_with_n_rnd_groups(d,
varGroups = varGroups, non_rnd = c("time", "geo"), rnd_rep = rnd_rep)))
Run the code above in your browser using DataLab