Skip to content

Instantly share code, notes, and snippets.

@ewoo
Created October 29, 2015 15:51
Show Gist options
  • Save ewoo/4c096a62bcadb5a3280d to your computer and use it in GitHub Desktop.
Save ewoo/4c096a62bcadb5a3280d to your computer and use it in GitHub Desktop.
A Random Projection function using "mlr" package in R.
# Written by Adam Acosta
randomProjection <- function(A, k) {
if (!is.matrix(A)) {
tmp <- as.matrix(A)
} else {
tmp <- A
}
p <- ncol(tmp)
set.seed(as.numeric(format(Sys.time(), '%S')))
R <- matrix(data = rnorm(k), nrow = k, ncol = p)
tmp <- apply(tmp, 2, function(x) (x - mean(x)) / sd(x))
as.data.frame(t(R %*% t(tmp)))
}
@SiddhuNITPY
Copy link

A Package is Available for performing Random Projection in R language
https://cran.r-project.org/web/packages/RandPro/index.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment