Trouble with grouping by and counting in r I have a data.frame called world. This data frame lists countries in column name.y, I have a column for languages named languages.  I need to List the names of countries where more than 4 languages are spoken.

My first take on this is to aggregate country and languages.

language &lt;- data.frame(table(World$name.y,World$language))


when I run head(language) it doesn't work out.
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)