I got a klugey solution but feel silly writing so much code for what seems simple. This goes pretty fast with lists of a few dozen MB, so I don't need to improve efficiency. But I'd still like help.
I have a large list (n elements, each one is a vector of length m). I need to get the m minimum values across all n elements (what I mean is obvious in code if this is confusing). There are NAs, in some cases with 0 complete cases and in most cases with >=1 complete case. I wrote some code that works fine but it feels like there should be a much simpler way to get here. Can you streamline this code?
Specifically, is there a way to avoid the conditional for the minimum function, and is there an apply-family function that would let me avoid the first cbind?
# make data
rawval<-replicate(10, sample(c(1:10, NA), size = 10, replace =T)
, simplify = F)
# this seems clunky, does this function have a name?
mymin<-function(x)ifelse(all(is.na(x)), NA, min(x, na.rm =T))
# I don't see why I should need two apply family functions here
tomin<-sapply(rawval, cbind) %>% apply(MARGIN = 1, FUN = mymin)
Apologies, I suspect this is a duplicate question :(