Message-ID: <CAPtbhHwO+W_QEdFL86gDcvuzEDAN0nHRD6nwnH=g4dBFRzX3fA@mail.gmail.com>
Date: 2013-01-04T16:38:02Z
From: Suzen, Mehmet
Subject: non-consing count
In-Reply-To: <CAAxdm-7C3SVn85fJeiUVyvK7OfWmcHpaPtaAUMevt_LbEGGBeQ@mail.gmail.com>
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.