to.ncpen.x.mat {ncpen} | R Documentation |
Convert a data.frame
to a ncpen
usable matrix
.
Description
This automates the processes of to.indicators
and interact.data
.
First, it converts categorical variables to a series of indicators.
All other numerical and logical variables are preserved.
Then, if interact.all == TRUE
, all the variables are interacted.
Usage
to.ncpen.x.mat(df, base = NULL, interact.all = FALSE,
base.cols = NULL, exclude.pair = NULL)
Arguments
df |
a |
base |
a base category removed from the indicator variables. This |
interact.all |
indicates whether to interact all the columns ( |
base.cols |
indicates columns derived from a same column. For example, if |
exclude.pair |
the pairs will be excluded from interactions. This should be a |
Value
This returns an object of matrix
.
Examples
df = data.frame(num = c(1, 2, 3, 4, 5),
ctr = c("K", "O", "R", "R", "K"),
logi = c(TRUE, TRUE, FALSE, FALSE, TRUE),
age = c(10, 20, 30, 40, 50),
age_sq = c(10, 20, 30, 40, 50)^2,
loc = c("b", "a", "c", "a", "b"),
FTHB = c(1,0,1,0,1),
PRM = c(0,1,0,1,0),
PMI = c(1,1,0,0,0));
to.ncpen.x.mat(df, interact.all = TRUE,
base.cols = c("age"),
exclude.pair = list(c("FTHB", "PRM")));