1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
prcomp1<-function (x, retx = TRUE, center = TRUE, scale. = FALSE, tol = NULL)
{
x <- as.matrix(x)
x <- scale(x, center = center, scale = scale.)
s <- svd(x, nu = 0, LINPACK=FALSE)
if (!is.null(tol)) {
rank <- sum(s$d > (s$d[1] * tol))
if (rank < ncol(x))
s$v <- s$v[, 1:rank, drop = FALSE]
}
s$d <- s$d/sqrt(max(1, nrow(x) - 1))
dimnames(s$v) <- list(colnames(x), paste("PC", seq(len = ncol(s$v)),
sep = ""))
r <- list(sdev = s$d, rotation = s$v)
if (retx)
r$x <- x %*% s$v
class(r) <- "prcomp1"
r
} |
Partager