# NOT RUN {
# Sum of 1:x
gen.vector(sum(1:x), x = 1:10)
# Same as above, but return as text
gen.list("sum of 1 to {x} is {sum(1:x)}", x = 1:5)
# A list containing vectors [1], [1, 2], [1, 2, 3], ...
gen.list(gen.vector(i, i = 1:n), n = 1:10)
# A data frame of tuples (x_1, x_2, x_3) summing up to 10
gen.data.frame(c(x_1, ..., x_3), x_ = 1:10, x_1 + ... + x_3 == 10)
# Same as above, but restrict to ascending tuples with x_i <= x_(i+1)
gen.data.frame(c(x_1, ..., x_3), x_1 = 1:10, x_2 = x_1:10, x_3 = x_2:10,
x_1 + ... + x_3 == 10)
# A data frame containing the numbers in 2:20, the sum of their divisors
# and a flag if they are "perfect" (sum of divisors equals the number)
gen.data.frame(list(n, sumdiv, perfect = (n == sumdiv)), n = 2:20,
sumdiv = sum(gen.vector(x, x = 1:(n-1), n %% x == 0)))
# A diagonal matrix with (1, ..., 5) on the diagonal
gen.matrix(if (i == j) i else 0, i = 1:5, j = 1:5)
# }
Run the code above in your browser using DataLab