I have a list of dataframes dataframes_list. For an example, I put the dput(dataframes_list) at the bottom. I want to sort all dataframes in the li
lapply is your friend ;)
You could do it using arrange from dplyr pacakge like this:
library(dplyr)
newlist <- lapply(dataframeslist, function(df){arrange(df,enrichment)})
or without dplyr like this:
newlist <- lapply(dataframeslist, function(df){df[order(df$enrichment),]})
Use lapply:
sorted_dataframes_list <- lapply(dataframes_list, function(df){
df[order(df$enrichment),]
})
This is a data.table solution.
require(data.table)
# Convert to data.table
dataframes_list <- lapply(dataframes_list, data.table)
# Setting a key sorts a data.table
lapply(dataframes_list, setkey, enrichment)