# single period
n <- 5
c1 <- function(n) data.frame(a = rnorm(n))
c2 <- function(n) data.frame(b = rnorm(n))
x <- c1 %join% c2
x(n)
# adding covariates that remain constant when sampling
x <- c1 %join% data.frame(b = rnorm(n))
all.equal(x(n)$b, x(n)$b)
# adding multiple anonymous functions require parenthesis enclosing, with
# the exception of the last function
x <- c1 %join%
(\(n) data.frame(b = rnorm(n))) %join%
\(n) data.frame(c = rnorm(n))
x(n)
# multiple periods
base <- setargs(covar_loggamma, normal.cor = .5)
x <- base %join%
function(n) list(
data.frame(a = rbinom(n, 1, 0.5)),
data.frame(a = rbinom(n, 1, 0.5))
)
x(n)
# constant covariate
x <- base %join% list(data.frame(a = 0), data.frame(a = 1))
x(n)
# baseline covariate
x <- base %join% function(n) data.frame(w = rnorm(n))
x(n)
Run the code above in your browser using DataLab