Q:

what is the most efficient way to find the most common value in a vector?

I'm trying to create a function to solve this puzzle:
An Arithmetic Progression is defined as one in which there is a constant difference between the consecutive terms of a given series of numbers. You are provided with consecutive elements of an Arithmetic Progression. There is however one hitch: exactly one term from the original series is missing from the set of numbers which have been given to you. The rest of the given series is the same as the original AP. Find the missing term.
You have to write the function findMissing(list), list will always be at least 3 numbers. The missing term will never be the first or last one.
The next section of code shows my attempt at this function. The site i'm on runs tests against the function, all of which passed, as in they output the correct missing integer.
The problem i'm facing is it's giving me a timeout error, because it takes to long to run all the tests. There are 102 tests and it's saying it takes over 12 seconds to complete them. Taking more than 12 seconds means the function isn't efficient enough.
After running my own timing tests in RStudio it seems running the function would take considerably less time than 12 seconds to run but regardless i need to make it more efficient to be able to complete the puzzle.
I asked on the site forum and someone said "Sorting is expensive, think of another way of doing it without it." I took this to mean i shouldn't be using the sort() function. Is this what they mean?
I've since found a few different ways of getting my_diff which is calculated using the sort() function. All of these ways are even less efficient than the original way of doing it.
Can anyway give me a more efficient way of doing the sort to find my_diff or maybe make other parts of the code more efficient? It's the sort() part which is apparently the inefficient part of the code though.
find_missing <- function(sequence){

  len <- length(sequence)

  if(len > 3){
    my_diff <- as.integer(names(sort(table(diff(sequence)), decreasing = TRUE))[1])

    complete_seq <- seq(sequence[1], sequence[len], my_diff)
  }else{
    differences <- diff(sequence)
    complete_seq_1 <- seq(sequence[1],sequence[len],differences[1])
    complete_seq_2 <- seq(sequence[1],sequence[len],differences[2])
    if(length(complete_seq_1) == 4){
      complete_seq <- complete_seq_1
    }else{
      complete_seq <- complete_seq_2
    }
  }

  complete_seq[!complete_seq %in% sequence]

}

Here are a couple of sample sequences to check the code works:
find_missing(c(1,3,5,9,11))
find_missing(c(1,5,7))

Here are some of the other things i tried instead of sort:
1:
library(pracma)
Mode(diff(sequence))

2:
library(dplyr)
(data.frame(diff_1 = diff(sequence)) %>% 
  group_by(diff_1) %>%
  summarise(count = n()) %>%
  ungroup() %>%
  filter(count==max(count)))[1]

3:
MaxTable <- function(sequence, mult = FALSE) {

  differences <- diff(sequence)
  if (!is.factor(differences)) differences <- factor(differences)
  A <- tabulate(differences)
  if (isTRUE(mult)) {
    as.integer(levels(differences)[A == max(A)])
  } 
  else as.integer(levels(differences)[which.max(A)])
}

A:

Here is one way to do this using seq. We can create a sequence from minimum value in sequence to maximum value in the sequence having length as length(x) + 1 as there is exactly one term missing in the sequence. 
find_missing  <- function(x) {
  setdiff(seq(min(x), max(x), length.out = length(x) + 1), x)
}

find_missing(c(1,3,5,9,11))
#[1] 7
find_missing(c(1,5,7))
#[1] 3

A:

This approach takes the diff() of the vector - there will always be one difference higher than the others. 
find_missing <- function(x) {
  diffs <- diff(x)
  x[which.max(diffs)] + min(diffs)
}

find_missing(c(1,3,5,9,11))
[1] 7
find_missing(c(1,5,7))
[1] 3

A:

There is actually a simple formula for this, which will work even if your vector is not sorted...
find_missing <- function(x) {
   (length(x) + 1) * (min(x) + max(x))/2 - sum(x)
   }

find_missing(c(1,5,7))
[1] 3

find_missing(c(1,3,5,9,11,13,15))
[1] 7

find_missing(c(2,8,6))
[1] 4

It is based on the fact that the sum of the full series should be the average value times the length.

