I am using R to do some PCA analysis. Everything was working fine until it occurred to me that I should be dealing with the transpose of my data set. However when I tried to do PCA on the transposed data set I could not get it to work out!
> sum(is.na(data_t))
[1] 1367
> dim(data_t)
[1] 599 9505
> data_t[1:4,1:4]
2'-PDE 7A5 A1BG A2M
TCGA.A1.A0SD.01A.11R.A115.07 0.0153750 2.4105 0.9493333 0.24200
TCGA.A1.A0SE.01A.11R.A084.07 0.4669375 0.3635 0.2798333 1.03850
TCGA.A1.A0SH.01A.11R.A084.07 -0.0295625 1.8550 0.7486667 1.16050
TCGA.A1.A0SJ.01A.11R.A084.07 0.7919375 1.4080 0.7500000 1.67775
> pca2<-princomp(~.,data=data_t, na.action=na.omit)
Error in `[.data.frame`(mf, , x) : undefined columns selected
> pca2<-princomp(data_t, na.action=na.omit)
Error in princomp.default(data_t, na.action = na.omit) :
'princomp' can only be used with more units than variables
Turns out that you cannot use princomp if you have more variables than units. But you can use prcomp (see R - 'princomp' can only be used with more units than variables) but I still get errors with that!
> pca2<-prcomp(data_t,na.action=na.omit)
Error in svd(x, nu = 0) : infinite or missing values in 'x'
> pca2<-prcomp(~ ., data=data_t, na.action=na.omit, scale=TRUE)
Error in `[.data.frame`(mf, , x) : undefined columns selected