Skip to content

Instantly share code, notes, and snippets.

View jdmar3's full-sized avatar

John D. Martin III jdmar3

View GitHub Profile
@jdmar3
jdmar3 / dataframe_split_sort.R
Created March 30, 2014 19:03
Snippet to split dataframe into multiple dataframes using a sorting value
# Split multi-year dataframe into smaller dataframes by year.
# This will label the new dataframes as "year1997", "year1998", etc.
# Replace DATAFRAME below with the name of your dataframe object
invisible(lapply(split(DATAFRAME, DATAFRAME$year), function(x) {
assign(paste0("year", x$year[1]), x, pos=.GlobalEnv) }))
# You can change the sort value to country or whatever other variable
# you like by changing all instances of "year" to whatever the other