Find the mode value and frequency in R
You do not need a custom function to do this. Let dplyr handle it. Assuming your data is in a dataframe named df, here is what it might look like:

df %&gt;%                                       # Set up the pipe
subset(complete.cases(df)) %&gt;%               # Removes rows with NA values
group_by(Name) %&gt;%                           # Groups by the Name column
count(Color) %&gt;%                             # Counts each Color by Name, creates a new column n
mutate(max = max(n)) %&gt;%                     # Creates a new column for the max(n) by Name
subset(n == max(n)) %&gt;%                      # Keeps only those rows where n equals max(n)
mutate(Keep == case_when(                    # Creates a dummy logical column named 'Keep'
   n &gt; 1 ~ TRUE,                             # That is TRUEfor n &gt; 1 to keep ties
   n == 1 &amp; Color == head(Color, 1) ~ TRUE,  # That is TRUE for the first row of n = 1
   TRUE ~ FALSE)) %&gt;%                        # That is FALSE for all other cases
subset(Keep) %&gt;%                             # Keeps only those rows where Keep is TRUE
select(Name, Mode = Color, n)                # Keeps only the Name, Color, and n columns and
                                             # renames Color as Mode


Here is the output

 # A tibble: 3 x 3
 # Groups:   Name [3]
   Name  Mode   Count
   &lt;fct&gt; &lt;fct&gt;  &lt;int&gt;
 1 Bob   Green      3
 2 Drew  Blue       1
 3 Jim   Blue       2
 4 Jim   Red        2


If you want a function, then wrap this up in a function definition:

my_mode_func &lt;- function(df){
df %&gt;% 
   subset(complete.cases(df)) %&gt;%
   group_by(Name) %&gt;%
   count(Color) %&gt;%
   mutate(max = max(n)) %&gt;%
   subset(n == max) %&gt;%
   mutate(Keep = case_when(
      n &gt; 1 ~ TRUE,
      n == 1 &amp; Color == head(Color,1) ~ TRUE,
      TRUE ~ FALSE)) %&gt;%
   subset(Keep) %&gt;%
   select(Name, Mode = Color, Count = n)
}