Question about R mode

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Question about R mode

djackson

Hello all,

I am using R to perform certain calculations on huge amounts of data.  In short I need a function that does the mode function, ie returns the most common element.  I looked at the mode function in R but it seems to return the type of the data element you give it.  Does such a method exist?  I have tried googling this to no avail as all the results lead me back to the mode function I do not want.

Thanks,

Don
     
        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Question about R mode

Paul Hiemstra
[hidden email] wrote:
> Hello all,
>
> I am using R to perform certain calculations on huge amounts of data.  In short I need a function that does the mode function, ie returns the most common element.  I looked at the mode function in R but it seems to return the type of the data element you give it.  Does such a method exist?  I have tried googling this to no avail as all the results lead me back to the mode function I do not want.
>  
I googled for "R calculate mode", the first hit was this result:

http://www.mail-archive.com/r-help@.../msg30197.html

this is probably what you want.

cheers,
Paul

> Thanks,
>
> Don
>      
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>  

--
Drs. Paul Hiemstra
Department of Physical Geography
Faculty of Geosciences
University of Utrecht
Heidelberglaan 2
P.O. Box 80.115
3508 TC Utrecht
Phone:  +3130 274 3113 Mon-Tue
Phone:  +3130 253 5773 Wed-Fri
http://intamap.geo.uu.nl/~paul
http://nl.linkedin.com/pub/paul-hiemstra/20/30b/770

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Question about R mode

Patrick Burns
On 15/04/2010 08:52, Paul Hiemstra wrote:

> [hidden email] wrote:
>> Hello all,
>>
>> I am using R to perform certain calculations on huge amounts of data.
>> In short I need a function that does the mode function, ie returns the
>> most common element. I looked at the mode function in R but it seems
>> to return the type of the data element you give it. Does such a method
>> exist? I have tried googling this to no avail as all the results lead
>> me back to the mode function I do not want.
> I googled for "R calculate mode", the first hit was this result:
>
> http://www.mail-archive.com/r-help@.../msg30197.html

But be careful: creating your own function
called 'mode' will mask the standard 'mode'
function.

If you desire to remain sane, name it something
else.

Pat

>
> this is probably what you want.
>
> cheers,
> Paul
>> Thanks,
>>
>> Don
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>

--
Patrick Burns
[hidden email]
http://www.burns-stat.com
(home of 'Some hints for the R beginner'
and 'The R Inferno')

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Question about R mode

Greg Snow-2
In reply to this post by djackson
The mode is a well defined concept for theoretical distributions, but much less well defined when applied to data.  Some attempts at getting the mode of data actually returns a quirk of rounding rather than anything informative about the data and the distribution that it represents.  This is especially true when the data is supposed to represent and underlying continuous distribution.  If the theorized distribution is discrete (Poisson, binomial, etc.) then the mode may be more meaningful (but can still be the result of a quirk of rounding).  For discrete distributions you can just use the table function to get all the counts and look for the largest (and look for other similar values to see if your single "mode" is really meaningful).  For continuous distributions you need to decide what you really want and what level of approximation you are willing to live with and what assumptions you are willing to make (one simple approach is just look at the histogram, if there is a c!
 lear peak, then that gives you a modal range).


--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
[hidden email]
801.408.8111


> -----Original Message-----
> From: [hidden email] [mailto:r-help-bounces@r-
> project.org] On Behalf Of [hidden email]
> Sent: Wednesday, April 14, 2010 8:55 PM
> To: [hidden email]
> Subject: [R] Question about R mode
>
>
> Hello all,
>
> I am using R to perform certain calculations on huge amounts of data.
> In short I need a function that does the mode function, ie returns the
> most common element.  I looked at the mode function in R but it seems
> to return the type of the data element you give it.  Does such a method
> exist?  I have tried googling this to no avail as all the results lead
> me back to the mode function I do not want.
>
> Thanks,
>
> Don
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.