I was surprised this morning, that it seems as though the min() function does not work as *I* anticipated when given vector arguments. For example: a <- 1:10 b <- c(rep(1, times=5), rep(10, times=5)) Result:> min(a,b)1 What I actually wanted was a term by term minimum, i.e.: ifelse(a<=b, a, b) 1 1 1 1 1 6 7 8 9 10 Am I losing much in terms of computation power if I use the ifelse? I'm a little worried, because in implementation my vectors are quite long, and I will be computing the min of many of them, min(a,b,c,d,e,f) where a through f are all vectors of the same length. Any insight that can be provided is much appreciated. [[alternative HTML version deleted]]
Try this: pmin(a, b) On Tue, Dec 9, 2008 at 2:58 PM, Brigid Mooney <bkmooney@gmail.com> wrote:> I was surprised this morning, that it seems as though the min() function > does not work as *I* anticipated when given vector arguments. > > For example: > a <- 1:10 > b <- c(rep(1, times=5), rep(10, times=5)) > > Result: > > min(a,b) > 1 > > What I actually wanted was a term by term minimum, i.e.: > ifelse(a<=b, a, b) > 1 1 1 1 1 6 7 8 9 10 > Am I losing much in terms of computation power if I use the ifelse? > > I'm a little worried, because in implementation my vectors are quite long, > and I will be computing the min of many of them, min(a,b,c,d,e,f) where a > through f are all vectors of the same length. > > Any insight that can be provided is much appreciated. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]
Dear Brigid, Try: pmin(a,b) HTH, Jorge On Tue, Dec 9, 2008 at 11:58 AM, Brigid Mooney <bkmooney@gmail.com> wrote:> I was surprised this morning, that it seems as though the min() function > does not work as *I* anticipated when given vector arguments. > > For example: > a <- 1:10 > b <- c(rep(1, times=5), rep(10, times=5)) > > Result: > > min(a,b) > 1 > > What I actually wanted was a term by term minimum, i.e.: > ifelse(a<=b, a, b) > 1 1 1 1 1 6 7 8 9 10 > Am I losing much in terms of computation power if I use the ifelse? > > I'm a little worried, because in implementation my vectors are quite long, > and I will be computing the min of many of them, min(a,b,c,d,e,f) where a > through f are all vectors of the same length. > > Any insight that can be provided is much appreciated. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]