On 4 January 2013 16:53, jim holtman <jholt...@gmail.com> wrote: > Is performance a concern? How often are you going to do it and what > other parts of your script also take longer? Why are you concerned > about allocating/discarding two vectors?
I think Sam's question was about additional memory introduced by which. For example: > x <- c(1, 0, 0, 1, 0, 2, 0) > wx <- which(x==0) > object.size(wx) 56 bytes > object.size(x) 104 bytes If you have very large vector, a time series for example. This would make a lot of difference. I am not sure how 'sum' internally handles, but As I said earlier, a special function in C might be faster then length-which couple or sum, that counts occurrences as it goes, so it could get the result in one go, maybe like x %count% 0. One can implement a recursive function to do this in R interpreter level, but not sure about recursion depth memory requirement. ______________________________________________ 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.