[R] non-consing count

Suzen, Mehmet msuzen at gmail.com
Fri Jan 4 17:38:02 CET 2013


On 4 January 2013 16:53, jim holtman <jholtman at 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.




More information about the R-help mailing list