[R] Measures of central tendency - mode
Spencer Graves
spencer.graves at pdf.com
Fri Jan 30 23:56:42 CET 2004
Evidently, I didn't read your question carefully enough. If you
want the mode of continuous data, that is not well defined, though there
are devices to estimate such assuming, e.g., a specific distribution or
a general unimodal distribution or ... . This was discussed last Dec.
12-13 by Ted Harding, Brian Ripley and others. If you are interested,
you can go www.r-project.org -> search -> "R site search" -> "harding
mode". When I did this just now, the first hit was an email on how to
find the mode using a kernel density estimator. Clicking "next in
thread" a couple of times led me to a comment by Brian Ripley with a
pointer to a document discussing this.
... in case you are interested in more than what you already have.
spencer graves
Patrick E. McKnight wrote:
>Thanks to Andy Liaw and J.R. Lockwood for your suggestions. The which.max() worked great along with the rownames. The complete solution for me was:
>
>a <- table(varname)
>
>
>>my.mode <- rownames(a)[which.max(a)]
>>my.mode
>>
>>
>[1] "1"
>
>Amazing how a simple concept such as mode can present problems for us. Thanks again.
>
>To reply to Spencer Graves' question, I didn't find the disucssion via search. I guess I might have overlooked the thread if it were titled kernel density since that seemed far too technical for this basic topic. Sorry if I cluttered up the list though.
>
>Cheers,
>
>Patrick
>
>
>On Fri, 30 Jan 2004 16:47:54 -0500 (EST)
>"J.R. Lockwood" <lockwood at rand.org> wrote:
>
>
>
>>it is an annoyance that table() provides the values being tables as
>>the rownames of the resultant vector. you can do something like:
>>
>>a<-table(x)
>>rownames(a)[which.max(a)]
>>
>>On Fri, 30 Jan 2004, Patrick E. McKnight wrote:
>>
>>
>>
>>>Date: Fri, 30 Jan 2004 13:55:19 -0700
>>>From: Patrick E. McKnight <pem at theriver.com>
>>>To: "r-help at stat.math.ethz.ch" <r-help at stat.math.ethz.ch>
>>>Subject: [R] Measures of central tendency - mode
>>>
>>>Greetings,
>>>
>>>This seems too rudimentary to ask but for the life of me I cannot locate a readily easy method to compute the univariate mode. I know "mode" is not correct and "table" provides a reasonable count but I figured there would be an easy way to extract the value from the table after I do something like:
>>>
>>>max(table(mydadat$myvar))
>>>
>>>unfortunately it only returns the max count and not the value that is observed most. Would some kind soul help me out with this seemingly trivial problem?
>>>
>>>Thanks in advance.
>>>
>>>Cheers,
>>>
>>>Patrick
>>>
>>>______________________________________________
>>>R-help at stat.math.ethz.ch mailing list
>>>https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>>>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>>>
>>>
>>>
>>J.R. Lockwood
>>412-683-2300 x4941
>>lockwood at rand.org
>>http://www.rand.org/methodology/stat/members/lockwood/
>>
>>
>>
More information about the R-help
mailing list