expand: expand grid with numerical component

View source: R/expand.R

expandR Documentation

expand grid with numerical component

Description

expand combinations with range of numerical variable

Usage

expand(formula, data, res, ...)

Arguments

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

Details

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

Value

a data frame with columns as specified in formula and if given as in ...

Examples

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")

gobbios/cfp documentation built on April 11, 2022, 2:22 a.m.