I am using the function prcomp
to calculate the first two principal components. However, my data has some NA values and therefore the function throws an error.
Yeah, it looks like a "feature" (bug) that na.action
is completely ignored unless you use the formula
interface. This has been brought up before on the R Development list.
I think that this should be documented or flagged as a bug.
Just to be clear, this would work because it accesses the formula interface:
prcomp(~V1+V2, data=d, center = TRUE, scale = TRUE, na.action = na.omit)
Another solution if you're not willing to use formula interface is
prcomp(na.omit(d), center = TRUE, scale = TRUE)
which consist of applying na.omit
directly to the data frame.