I have split up a dataframe into a list of sub-dataframes (sub_dfs) using dplyr::group_split. These sub_dfs contain data which I then create a separate plot for each. However, I want to create these plots in a specific order.
Every sub_df has a column called ‘rank’. I want to create my plots in ascending order of:
(sub_df$rank)[1]
How can I achieve this?
I have tried to find an argument of dplyr::group_split that allows me to controll the ordering of the list it outputs. But I have had no luck.
I have also tried to concisely re-order the list after its creation. I can extract the relevant ranks from the list by:
extract_rank <- function(sub_df){as.numeric(return(sub_df[1,’rank’])}
ranking <- lapply(list, extract_rank)
…and ranking = c(10, 8, 3, 4, 6, 1…) tells me that the first sub_df in list should actually be in the 10th position etc.
Can I somehow use ranking to re-order my list of sub_dfs?
Isaac Feldman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.