I have a dataset with 200 rows and 20 columns where I would like to perform a PCA on using prcomp()
in R. However this doesn't work because my first column is listed as integer when I do str(x)
. The first column has numbers of between 0 and 4 which indicates the type of heating that was used to obtain my dataset. So this also has to be used in the PCA because I know the type of heating has an effect on the other 19 columns but I'm unable to start the PCA because it's listed as an integer. How can I solve this?
The column has important info and I would like to work with this info as well but I cannot because it's listed as integer instead of numeric and I when I try as.numeric() it says "Error: (list) object cannot be coerced to type 'double'"
.
I solved it using
dat_test$heating<-as.numeric(as.character(dat_test$heating))
str(dat_test)
But my PCR doesn't work still.
data.prcomp<-prcomp(dat_test,scale.=TRUE,na.rm=TRUE)
returns
Error in svd(x, nu = 0) : infinite or missing values in 'x'
I have 2 NA values in total. This should still work with na.rm
or na.action=na.omit
but it doesn't.