I want to extract the minimum value of each element of several matrix that are stored inside a list. I'm using pmin:
do.call(pmin, mylist)
The problem is that some elements of those matrix are NAs, and pmin yields a NA where I want it to yield the minimum value after excluding the NAs. I tried to solve my problem using do.call(pmin(na.rm=T), mylist)
but I get an error. I also tried with this answer: data.table and pmin with na.rm=TRUE argument, but I get the error because .SD is not on the environment. Simple code for a similar problem would be:
mymat1 <- matrix(rnorm(10), ncol=2)
mymat2 <- matrix(rnorm(10), ncol=2)
mymat2[2,2] <- NA
mymat3 <- matrix(rnorm(10), ncol=2)
mylist <- list(mymat1, mymat2, mymat3)
do.call(pmin, mylist)
I get a NA in the position [2,2] of the resulting matrix, and I want to get the minimum values ignoring NAs. Any suggestions? Thank you.
list(na.rm=TRUE)
justc(mylist, na.rm = TRUE)
will work – Baum