3

I am performing principal components analysis on a dataset that I have. Here is the code that I have used thus far:

pca1<-prcomp(data1,center=TRUE,scale=TRUE)
summary(pca1)
pca1$rotation
pca1$sdev^2
library("devtools")
library("ggbiplot")
plot1 <- ggbiplot(pca1,obs.scale=1, var.scale=1, groups=data2, ellipse=TRUE)

I get the error:

Error in `[.data.frame`(x, order(x, na.last = na.last, decreasing = decreasing)) : undefined columns selected For your reference, "data1" is a data frame with only numerical variables and "data2" contains one column of categorical variables by which I am trying to group the numerical variables. The two data sets have the same number of rows. I ran this exact code on very similar dataset previously with no issues.

Any suggestions on what may be the issue?

MLavoie
  • 9,671
  • 41
  • 36
  • 56
  • hi, give a look to https://stackoverflow.com/questions/14325880/pca-on-transposed-data – Irene Mar 26 '20 at 14:54
  • Thanks for the suggestion, but this one did not help. I had already removed missing values and using princomp instead of prcomp returned the same error. My data already had column names as well. – Stephanie Wedryk Mar 26 '20 at 15:44

0 Answers0