set.seed(1071)
design_mat <- cbind( data.frame(matrix(rnorm(5*100),ncol = 5)),
sample(sample(letters, 10), 100, replace = TRUE))
colnames(design_mat)[6] <- "factor_var"
test_that("Mean encoding works", {
new_mat <- encode_mean(design_mat, "factor_var")
expect_equal(ncol(new_mat), 10)
expect_equal(nrow(new_mat), 100)
expect_equal(sum(apply(new_mat,2, is.numeric)), 10)
new_mat <- encode_mean(design_mat, "factor_var", keep_factor = TRUE)
expect_equal(ncol(new_mat), 11)
expect_equal(nrow(new_mat), 100)
expect_equal(sum(unlist(lapply(new_mat, is.numeric))), 10)
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.