0

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.

TristanDM
  • 89
  • 6
  • Have you seen this discussion? http://stackoverflow.com/questions/12078291/r-function-prcomp-fails-with-nas-values-even-though-nas-are-allowed I think with the edit to your question solving the first part, this is probably a duplicate. – LJW Mar 13 '15 at 01:14
  • @LJW sorry... I found the post you referenced above without following anything but my own searches. I'm glad to see it has been confirmed. cheers. – miles2know Mar 13 '15 at 01:24

1 Answers1

0

well I have know idea what you're looking into. It seems rife for some hierarchical modelling. So prcomp doesn't have an na.rm argument. The function uses na.action for this.

So after looking into this specific solution - for a little bit - while standing on the shoulders of Giants I found this. I think it could work for you. I would also recommend that you dig a bit deeper into the methods you are attempting. A search would reveal more than you could ever know. Cheers.

prcomp(na.omit(dat_test), scale = TRUE)

Community
  • 1
  • 1
miles2know
  • 737
  • 8
  • 17