Description Usage Arguments Details Value Examples
View source: R/model_matrix_model.r
This function transforms a data.frame to matrix (or sparse matrix) based on a r formula. The mean different from model.matrix() function is that it outputs a class stored with the transformed matrix, as well as the transforming parameters which can be applied to new data.
1 2 3 4 5 6 7 8 9 |
rformula |
a formula, e.g. formula("~ 1+x1+x2"),"~ 1+x1+x2",or ~ 1+x1+x2 . Note the interpreting of the formula might be different slightly from model.matrix function. In model.matrix(),intercept column will be included in output matrix with or without "1" in the formula. But in ModelMatrixModel(),intercept column will be included in output matrix only when "1" is present. Moreover "0" or "." in the formula will be ignored. |
data |
a data.frame. |
sparse |
boolean, if TRUE return a sparse matrix, i.e. a "dgCMatrix" class. |
center |
boolean, if center the output. |
scale |
boolean, if scale the output. |
remove_1st_dummy |
boolean, if remove the first dummy variable in one hot key transformation. |
verbose |
boolean, if print out progress. |
see vignettes.
A ModelMatrixModel class,which includes the transformed matrix and the transforming parameters.
1 2 3 4 5 6 | library(ModelMatrixModel)
traindf= data.frame(x1 = sample(LETTERS[1:5], replace = TRUE, 20),
x2 = rnorm(20, 100, 5),
y = rnorm(20, 10, 2))
mm=ModelMatrixModel(~x1+x2,traindf,remove_1st_dummy = FALSE)
data.frame(as.matrix(head(mm$x,2)))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.