runningCount | R Documentation |
running count of occurences for each unique value in a vector
runningCount(x)
x: |
integer vector |
For an integer vector, returns a vector of equal length giving the number of times the i'th element occurs in the first i slots.
integer vector rv
; rv[i] =
sum(x[1:i] == x[i])
: despite the O(log(length(x))) call to order()
,
this works faster up to at least length(x) == 1E8 than a similar
version that first converts to a factor and then orders using
method="radix"
John Brzustowski jbrzusto@REMOVE_THIS_PART_fastmail.fm
runID = ceiling(10 * runif(100))
posInRun = runningCount(runID)
for (i in seq(along=runID)) if (posInRun[i] != sum(runID[1:i] == runID[i])) stop("runningCount failed!")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.