I think the sum way is the best.
On Fri, Apr 26, 2013 at 9:12 AM, Mikhail Umorin <mike...@gmail.com> wrote: > Hello, > > I am dealing with numeric vectors 10^5 to 10^6 elements long. The values > are > sorted (with duplicates) in the vector (v). I am obtaining the length of > vectors such as (v < c) or (v > c1 & v < c2), where c, c1, c2 are some > scalar > variables. What is the most efficient way to do this? > > I am using sum(v < c) since TRUE's are 1's and FALSE's are 0's. This seems > to > me more efficient than length(which(v < c)), but, please, correct me if I'm > wrong. So, is there anything faster than what I already use? > > I'm running R 2.14.2 on Linux kernel 3.4.34. > > I appreciate your time, > > Mikhail > [[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]] ______________________________________________ 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.