-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
On 30/03/11 02:47, Fernando Marmolejo Ramos wrote:
Dear R users
I?m aware that the package ?modest? is useful to find the mode in an array.
However, I?d like to know if someone has translated the ?mode? function
built-in
in MATLAB into R
Hello Rainer and Fernando,
Actually, I think this function should involve the which.max (not max):
Here is a tiny function to perform this (with smarter handeling of multiple
modes and giving proper warning in such cases)
The.mode - function(x, show_all_modes = F)
{
x_freq - table(x)
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
On 30/03/11 10:59, Tal Galili wrote:
Hello Rainer and Fernando,
Actually, I think this function should involve the which.max (not max):
Right - was not awarw of which.max - I would have used which(max(...)) -
which.max is much more elegant.
Here's my modest contribution:
smode-function(x){
xtab-table(x)
modes-xtab[max(xtab)==xtab]
mag-as.numeric(modes[1]) #in case mult. modes, this is safer
themodes-names(modes)
mout-list(themodes=themodes,modeval=mag)
return(mout)
}
(I
Dear R users
Im aware that the package modest is useful to find the mode in an array.
However, Id like to know if someone has translated the mode function built-in
in MATLAB into R language. This function finds the most frequent value in an
array
5 matches
Mail list logo