[R] calculating the mode in R...

Carl Witthoft carl at witthoft.com
Thu Mar 31 00:47:26 CEST 2011


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 called it 'smode' because there's a 'mode' func somewhere which is 
related to the data type or something)

Carl



More information about the R-help mailing list