# Principal Components for matrices with NA Classic List Threaded 4 messages Open this post in threaded view
|

## Principal Components for matrices with NA

 Hello, I have a matrix with 267 columns, all rows of which have at least one column missing (NA). All three methods i've tried (pcs, princomp, and prcomp) fail with either "Error in svd(zsmall) : infinite or missing values in 'x'" (latter two) or "Error in cov.wt(z) : 'x' must contain finite values only" The last one happens because of the check if (!all(is.finite(x))) in cov.wt Q: is there a way to do princomp or another method where every row has at least one missing column? I guess if missing values are thrown out, that leaves me with a zero row matrix. I could find the maximal set of columns such that there exists a subset of rows with non NA values for every column in the set  - what is an efficient way to do that? Kind Regards JS         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: Principal Components for matrices with NA

 Hello, > I could find the maximal set of columns such that there exists a subset of > rows with non NA values for every column in the set  - what is an efficient > way to do that? Try 'na.exclude' on the transpose matrix. Example: set.seed(1) x <- matrix(1:200, ncol=25) f <- function(x){x[sample(length(x), 1)] <- NA; x} x <- t(apply(x, 1, f)) x x.without.NA <- t(na.exclude(t(x))) Hope this helps, Rui Barradas