[Rd] Modes again

From: Gregor GORJANC <gregor.gorjanc_at_bfro.uni-lj.si>
Date: Fri 26 Nov 2004 - 21:25:11 EST


I write once more. I slightly modified your code Ross and now it returns all modes from the distribution. I changed the name of the funtion to distinguish the difference. I do not like the name simpleMode, however mode is already taken by another function (The (Storage) Mode of an Object).

It would be nice to have some additional options for number of observations in modes, however this is above my current programming skills in R. I don't like the use of cat for returning the result. That is the reason I am sending this mail also to R-devel list. Maybe anybody there can solve the issue. Quite some users asked for mode calculation function and it would really nice to have it in R by default.

modus <- function (x) {

# Returns the modes of a value set
# Based on Ross NELSONs code from 2004-11-16 (on R-help mailling list)

# create a table with the values sorted by frequency

     sortvar <- sort(table(x))

# get the max frequency
maxfreq <- max(sortvar)
# find values with high frequency
modeTable <- which(sortvar == maxfreq)
# get the name (value) of the most frequent value
themoderesult <- names(modeTable)
# Report
# data(CO2)
# modus(CO2$uptake)
# rm(CO2)


Lep pozdrav / With regards / Con respeto,
     Gregor GORJANC

University of Ljubljana
Biotechnical Faculty       URI: http://www.bfro.uni-lj.si
Zootechnical Department    mail: gregor.gorjanc <at> bfro.uni-lj.si
Groblje 3                  tel: +386 (0)1 72 17 861
SI-1230 Domzale            fax: +386 (0)1 72 41 005

R-devel@stat.math.ethz.ch mailing list
Received on Fri Nov 26 20:32:51 2004

This archive was generated by hypermail 2.1.8 : Fri 26 Nov 2004 - 21:12:04 EST