Re: [R] calculating the mode in R...

2011-03-30 Thread Rainer M Krug
-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

Re: [R] calculating the mode in R...

2011-03-30 Thread Tal Galili
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)

Re: [R] calculating the mode in R...

2011-03-30 Thread Rainer M Krug
-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.

[R] calculating the mode in R...

2011-03-30 Thread Carl Witthoft
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

[R] calculating the mode in R...

2011-03-29 Thread Fernando Marmolejo Ramos
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 language. This function finds the most frequent value in an array