I am searching for a function f counting for the number of occurences of certain values in a vector.
As example the inputs are:
value = c(1,3)
vec   = c(1,1,3,1,3,4,4,5,5,3,1)
And the output looks like:
1 3 
4 3 
For another input:
value = c(1,77,3,99)
vec   = c(1,1,3,1,3,4,4,5,5,3,1)
Output is:
1 77  3 99 
4  0  3  0 
So that it works also with characters, dates, etc, every type a vector can handle.
This function can do the job:
countOcurrences = function(values, vec)
{
    setNames(sapply(values, function(u) sum(vec==u)), values)
}
But I wonder if there are some functions existing in some unknown packages doing the job?
 
    