[R] Principal Components for matrices with NA

Rui Barradas rui1174 at sapo.pt
Mon Feb 27 21:57:07 CET 2012


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



--
View this message in context: http://r.789695.n4.nabble.com/Principal-Components-for-matrices-with-NA-tp4425930p4426040.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list