summaryrefslogtreecommitdiff
path: root/R/R/pca.R
blob: 85782e42d4e1e131298ef332509f03bb3707ae9b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
pca <- function(x, k=1,q=0.5){
  n <- nrow(x)
  d <- ncol(x)
  B <- matrix(0, n, k)
  U <- matrix(0, d, k)
  l <- 0

  res <- .C("pca_wrapper",
    n=as.integer(n),
    d=as.integer(d),
    q=as.numeric(q),
    k=as.integer(k),
    X=as.numeric(t(x)),
    B=as.numeric(B),
    U=as.numeric(U),
    l=l)
  list(B=matrix(res$B,n,k,T),U=matrix(res$U,d,k,T), Y=matrix(res$X,n,d,T), l=res$l)
}