0

I want to find how many maximum values in a data. I have used length but it gives me 1. The maximum value is 9 and I have two 9s, I want is to display 2. Is there a function in R that I can use?

data <- c(1, 3, 8, 9, 0, 9)
max(data)
length(max(data))
r2evans
  • 141,215
  • 6
  • 77
  • 149
Spencer
  • 23
  • 5
  • 2
    You could do `sum(data == max(data))`. – tmfmnk Sep 22 '21 at 15:22
  • 1
    or `sort(table(data),decreasing=TRUE)[1]` – r2evans Sep 22 '21 at 15:23
  • Related: [Counting the number of elements with the values of x in a vector](https://stackoverflow.com/questions/1923273/counting-the-number-of-elements-with-the-values-of-x-in-a-vector), where you apparently know how to calculate 'x'. – Henrik Sep 22 '21 at 15:39

1 Answers1

-1
data <- c(1, 3, 8, 9, 0, 9)
length(which(data==max(data)))