I’ve run this code
var <- c("A","A","A","A","B","B","B","B","B","B","C","C","C")
table(var)
> table(var)
var
A B C
4 6 3
The maximum frequency is 6, for factor "B".
Is there a function that just returns the name of the factor which has the highest frequency, "B".
Any help greatly appreciated. Thanks
>Solution :
A possible solution:
library(tidyverse)
var <- c("A","A","A","A","B","B","B","B","B","B","C","C","C")
table(var) %>% which.max %>% names
#> [1] "B"
In base R:
names(which.max(table(var)))