The below function calculated the Mode for my data. However, in case that the data freq are equal it chooses the first one. How is it possible to edit the Mode function so that if the values are same return the median value.
Mode <- function(x) {
ux <- unique(x)
ux[which.max(tabulate(match(x, ux)))] }
for example in case
id V Freq
1 A 40 1
2 B 23 1
3 C 3 1
it returns 40, which I need to return 23 as median when the freqs are same.