Loop to create a dataframe for each unique value of a categorical variable in R

Viewed 33

I am trying to create a data frame for each country. How can I create a loop to go through the Country variable to do this? My current dataset is small, so I can use piping. This is not practical for a worldwide dataset though.

Chile <- life_gdp %>%
  filter(Country == "Chile")
China <- life_gdp %>%
  filter(Country == "China")
Germany <- life_gdp %>%
  filter(Country == "Germany")
Mexico <- life_gdp %>%
  filter(Country == "Mexico")
USA <- life_gdp %>%
  filter(Country == "United States of America")
Zimbabwe <- life_gdp %>%
  filter(Country == "Zimbabwe")
0 Answers
Related