I have a dataframe where I have three columns that basically are Country, Year, and Value.
I am trying to extract a dataframe for each of the unique countries. I am using the dplyr
library like:
USA<-filter(df, Country=="USA")
I can filter all of the countries like that, but doing so seems like a very repetitive task, so I am trying to find a way of doing it more efficiently.
I am thinking in a For
cycle but I don't really know how to script it. Here is what I tried.
for(i in unique(df$Country)){
i<-filter(df, Country==i)
}
It actually generates a df but it only includes the observations for the last element in the unique(df$Country)
part.
Thank you very much.