PCA on transposed data
I had the same problem. For me, it worked when I assigned column names (other than numeric) to my data.frame
.
For example, when colnames(mydf)
was (1,2,3,4,5)
, I got this error:
Error in [.data.frame(mf, , x) : undefined columns selected
What I did was:
colnames(mydf) <- paste("var", 1:5, sep="")
and then ran the princomp
function:
mypca <- princomp(~. , data=myrdf, cor=F, na.action=na.exclude)
and had no problems.
Seems like R does not like it when there is missing data and you try to use a formula with all of the variables. So this ended up working:
pca2<-prcomp(na.omit(data_t), scale=TRUE)
of course this omits those columns with missing data.