remove_collinear <- function(x) {
combs <- utils::combn(seq_len(ncol(x)), 2)
collinear <- sapply(
seq_len(ncol(combs)),
function(i) {
compare_columns(x[[combs[1, i]]], x[[combs[2, i]]])
}
)
}
compare_columns <- function(a, b) {
a <- to_numeric(a)
b <- to_numeric(b)
length(stats::na.omit(unique(a - b))) == 1
}
to_numeric <- function(x) {
if (is.character(x)) {
x <- factor(x)
}
if (is.factor(x) || is.logical(x)) {
x <- as.numeric(x)
}
x
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.