Extend0rnd1 | R Documentation |
Setting attr(varGroups, "FunctionExtend0")
to a function
makes Extend0
behave differently
Extend0rnd1(data, varGroups, k = 1, rndSeed = 123)
Extend0rnd2(...)
Extend0rnd1b(...)
data |
data.frame within |
varGroups |
argument to |
k |
Number of rows generated is approx. |
rndSeed |
Internal random seed to be used |
... |
Extra unused parameters |
The point is to create a function that takes data
and varGroups
as input
and that returns a data frame with a limited number of combinations of the elements in varGroups
.
The example function here is limited to two varGroups elements.
a data frame
z <- SSBtoolsData("sprt_emp_withEU")[c(1, 5, 8, 14), ]
z$age[z$age == "Y15-29"] <- "young"
z$age[z$age == "Y30-64"] <- "old"
varGroups <- list(c("year", "geo", "eu"), data.frame(age = c("middle", "old")))
Extend0(z, varGroups = varGroups)
attr(varGroups, "FunctionExtend0") <- Extend0rnd1
Extend0(z, varGroups = varGroups)
attr(varGroups, "FunctionExtend0") <- Extend0rnd1b
Extend0(z, varGroups = varGroups)
attr(varGroups, "FunctionExtend0") <- Extend0rnd2
Extend0(z, varGroups = varGroups)
# To see what's going on internally. Data used only via nrow
varGroups <- list(data.frame(ab = rep(c("a", "b"), each = 4), abcd = c("a", "b", "c", "d")),
data.frame(AB = rep(c("A", "B"), each = 3), ABC = c("A", "B", "C")))
a <- Extend0rnd1(data.frame(1:5), varGroups)
table(a[[1]], a[[2]])
table(a[[3]], a[[4]])
a <- Extend0rnd1b(data.frame(1:5), varGroups)
table(a[[1]], a[[2]])
table(a[[3]], a[[4]])
a <- Extend0rnd2(data.frame(1:5), varGroups[2:1])
table(a[[1]], a[[2]])
table(a[[3]], a[[4]])
a <- Extend0rnd1(data.frame(1:100), varGroups)
table(a[[1]], a[[2]]) # Maybe smaller numbers than expected since duplicates were removed
table(a[[3]], a[[4]])
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.