# 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 <- data.frame(table(World$$name.y,World$$language))


when I run head(language) it doesn't work out.

• library(data.table); as.data.table(World)[, .(n=length(unique(language))),by=.(country)][n>=4,] – Valentas Dec 6 '18 at 7:36
• Sorry, but there was an error with this one. Error in [.data.table(as.data.table(World), , .(n = length(unique(language))), : column or expression 1 of 'by' or 'keyby' is type list. Do not quote column names. Usage: DT[,sum(colC),by=list(colA,month(colB))] – Chris Kehl Dec 6 '18 at 11:52

The dplyr package should be useful for this.
library(dplyr)