I have a dataframe (top_lang) that has a list of countries (country), the different languages spoken in each country (lang) and the number of people in each country that speak each language (langCountryPop). I have the langCountryPop column in descending order for each country and I would like to extract the largest number for each country.
A sample output I would like is:
x = data.frame("country"= c("American Samoa", "Andorra"), "lang" = c("Samoan", "Catalan"), "langCountryPop" = c(56700, 31000))
but repeated for all the countries in my dataset.
My attempt was:
top_lang %>% select(country, lang, langCountryPop) %>% arrange(country, max(langCountryPop))
But that hasn't outputted just the highest spoken language. Is there a function that will extract the max value within a group/is there another way to do this? Thanks!