expand | R Documentation |
expand combinations with range of numerical variable
expand(formula, data, res, ...)
formula |
a formula |
data |
the data set |
res |
numerical, the resolution for the numerical variable, i.e. the length of the sequence between minimum and maximum |
... |
further columns to be added with their value |
this function is an extension of expand.grid, i.e. it takes all the possible combinations of factors and binary variables in the data set and matches the numerical variable accordingly along a sequence from its minimum to its maximum
only combinations that actually occur in the data are returned
if res = 2
, the numerical variable will be returned as range
a data frame with columns as specified in formula
and if given as in ...
set.seed(123) xdata <- data.frame(pred1 = rnorm(100), pred2 = sample(c(0, 1), 100, TRUE), fac1 = sample(letters[1:3], 100, TRUE), fac2 = sample(LETTERS[7:8], 100, TRUE)) expand(~pred1 + fac1 + fac2, xdata, res = 3) expand(~pred2 + fac1 + fac2, xdata, res = 3) # adding columns expand(~pred2 + fac1 + fac2, xdata, res = 3, x = -17, y = "gg")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.