I have a dataset containing votes as columns and parliamentarians as rows. I want to compute an agreement index and therefore need the frequency of the mode.
A column looks e.g. like this
V1
1
3
2
1
1
2
1
I know the following code to show me the mode
getmode <- function(v) {
uniqv <- unique(v)
uniqv[which.max(tabulate(match(v, uniqv)))]
}
And I know how I R shows me the frequency of values
a <- table(df$V1)
print(a)
Is there a way that R takes the mode, in my example 1, and shows me how frequent it is, in my example 4?
You can just do
a <- table(df$V1)
max(a)
Or using your getmode function
sum(df$V1 == getmode(df$V1))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With