I am trying to learn about mode with R. I some code online, which I modified a little:
getmode <- function(v) {
uniqv <- unique(v)
first <- uniqv[which.max(tabulate(match(v, uniqv)))]
mode <- first
# cancel "first" occurrences
second<- uniqv[which.max(tabulate(match(v, uniqv)))]
mode <- second
# cancel "second" occurrences
third <- uniqv[which.max(tabulate(match(v, uniqv)))]
# cancel "third" occurrences
mode <- third
print(mode)
}
It returns only the first value (the max one), but I would like to print the first three ones. My idea was to get cancel all the occorrences of the first most frequent value (#), re-use the previous code and get the second most frequent value, cancel it and repeat again the routine to get the third. It seems easy, but I can't get it to work. Can anybody help me?
Otherwise, do you know any other way to get the first 3 max values of each attribute of my dataset?
Summary() works, but does not focus on the mode nor only on some of my attributes (it gives valuse for all attributes instead of the ones I want).