frequency of values of a matrix or vector
[m]=tabul(X [,order])
:X vector or matrix (of real or complex numbers or strings) : :order (optional) a character equal to “d” or “i” (default value
“d”)
:
This function computes the frequency of values of the components of a vector or matrix X of numbers or string characters :
:
The optional parameter order must be “d” or “i” (by default order=”d”) and gives the order (decreasing or increasing) the distinct values of X will be sorted.
// first example
X = [2 8 0 3 7 6 8 7 9 1 6 7 7 2 5 2 2 2 9 7]
m1 = tabul(X)
m2 = tabul(X, "i")
// second example
X = ["ba" "baba" "a" "A" "AA" "a" "aa" "aa" "aa" "A" "ba"]
m = tabul(X,"i")
// third example
n = 50000;
X = `grand`_(n,1,"bin",70,0.5);
m = tabul(X,"i");
`clf`_()
`plot2d3`_(m(:,1), m(:,2)/n)
`xtitle`_("empirical probabilities of B(70,0.5)")
// last example : computes the occurrences of words of the scilab license
text = `read`_(SCI+"/license.txt",-1,1,"(A)"); // read the scilab license
bigstr = `strcat`_(text," "); // put all the lines in a big string
sep = [" " "," "." ";" "*" ":" "-" """"]; // words separators
words = `tokens`_(bigstr, sep); // cut the big string into words
m = tabul(words); // computes occurrences of each word
[occ , p] = `gsort`_(m(2)); // sort by decreasing frequencies
results = [m(1)(p) `string`_(occ)] // display result
Wonacott, T.H. & Wonacott, R.J.; Introductory Statistics, fifth edition, J.Wiley & Sons, 1990.