#' Transform data from matrix of strings to data frame with factors or to model matrix
#'
#' @param x is an object
#' @return y is the output
#' @export
dataTransform <- function(dat, levels, model.Matrix = FALSE){
# Transform from matrix of strings to data.frame with factors
df <- as.data.frame(dat)
df[] <- lapply(df, factor, levels = levels)
if(model.Matrix){
df$c <- matrix(1L, nrow=nrow(as.matrix(dat)), ncol=1)
mat <- model.matrix(c~. , data = df)[,-1] #mat.sparse <- sparse.model.matrix(c~., data = df)
return(mat)
} else {
df[] <- lapply(df, as.numeric, levels = levels)
return(df)
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.