Trouble with grouping by and counting in r
The dplyr package should be useful for this.

library(dplyr)

World %&gt;%
  group_by(name) %&gt;%
  mutate(num_distinct_languages = n_distinct(language)) %&gt;%
  filter(num_distinct_lanagues &gt; 4)