[R] apply a function to a list of lists

arnaud gaboury @rn@ud@g@boury @end|ng |rom gm@||@com
Tue Sep 19 17:14:58 CEST 2023

I have a list of 9 lists called my.list. Each one of these 9 lists is
itself a list of 6 data.frames. Most of these data.frames have 0 rows and 0
I want to return all data.frames from the list with row numbers different
from 0.
I first created the following function:

non_empty_df <- function(l) {
    lapply(l, function(df) df[sapply(df, function(df) nrow(df) !=0)])

If I test this way: non_empty_df(my.list[1]) it does the job. It will
return the data.frame from the first list of my_list with rows.
Now I can't find a way to iterate the above function to all the 9 nested

Thank you for help

	[[alternative HTML version deleted]]

More information about the R-help mailing list