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?