First a general comment on the mode:
You should not use that approach to get the mode of (at least notionally) continuously distributed data; you're unlikely to have any repeated values (unless you have truly huge samples it would be a minor miracle, and even then various numeric issues could make it behave in somewhat unexpected ways), and you'll generally just get the minimum value that way. It would be one way to find one of the global modes in discrete or categorical data, but I probably wouldn't do it that way even then. Here are several other approaches to get the mode for discrete or categorical data:
x = rpois(30,12.3)
tail(sort(table(x)),1) #1: category and count; if multimodal this only gives one
w=table(x); w[max(w)==w] #2: category and count; this can find more than one mode
which.max(table(x)) #3: category and *position in table*; only finds one mode
If you just want the value and not the count or position, names()
will get it from those
To identify modes (there can be more than one local mode) for continuous data in a basic fashion, you could bin the data (as with a histogram) or you could smooth it (using density
for example) and attempt to find one or more modes that way.
Fewer histogram bins will make your estimate of a mode less subject to noise, but the location won't be pinned down to better than the bin-width (i.e. you only get an interval). More bins may allow more precision within a bin, but noise may make it jump around across many such bins; a small change in bin-origin or bin width may produce relatively large changes in mode. (There's the same bias-variance tradeoff all over statistics.)
Note that summary
will give you several basic statistics.
[You should use sd(x)
rather than sqrt(var(x))
; it's clearer for one thing]
--
In respect of q.2 yes; you could certainly show mean and median of the data on a display such as a histogram or a box plot. See here for some examples and code that you should be able to generalize to whatever cases you need.