r - matrix containing number of occurrence corresponding to each element in the matrix -
i have matrix, suppose
a = [1 2 3 1 1 1 2 3]
i want find number of times number appeared in matrix. output matrix i/p
b = [1 1 1 2 3 4 2 2]
i.e. 1 appeared 4 times in array, hence last value corresponding 1 4.
unique
, sum unique
not because gives total number of times element occured, want matrix increases count every time occurs.
try this:
b = ave(a,a,fun=function(x) 1:length(x))
Comments
Post a Comment