On Tue, 19 Sep 2023 17:14:58 +0200
arnaud gaboury wrote:
> 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
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
columns.
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 <- funct
Thank you for your help.
Your explanations have been very useful.
Stefano
Da: Rui Barradas [ruipbarra...@sapo.pt]
Inviato: venerdì 22 maggio 2015 20.26
A: Stefano Sofia; r-help@r-project.org
Oggetto: Re: [R] apply a function to a list of data frames
Hello,
You should change your function to accept only one argument, the
data.frames, and then use lapply (not sapply).
Something like the following.
calc <- function(dat)
{
bias_dmo_max <- round(mean((dat$dmo_12-dat$Eonestep_12), na.rm=TRUE),
digits=2)
rmse_dmo_max <- round(sqrt(mean((dat$d
Where is your code? I see no invocation of sapply.
-- Bert
Bert Gunter
Genentech Nonclinical Biostatistics
(650) 467-7374
"Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom."
Clifford Stoll
On Fri, May 22, 2015 at 11:02 AM, Stefano Sofia
wrote:
> D
Dear R-users,
given a list of dataframes (like below reported), for each month I need to
apply a function (called calc).
The result should be written in a new list of data frames, one row for each
month.
I have been trying to use sapply, with no success.
Could somebody help me in this?
$df1
da
Hi,
You may also flatten the list of lists and apply the function. In the example I
provided,
lapply(do.call(c,unlist(lst1,recursive=FALSE)),sum)
#or
use one of the functions from this link
http://stackoverflow.com/questions/8139677/how-to-flatten-a-list-to-a-list-without-coercion
lapply(flatt
Hi,
You may try:
(Please provide a reproducible example.)
lst1 <- list(list(list(c(14L, 13L, 5L, 4L, 9L), c(14L, 16L, 13L, 2L)),
list(c(3L, 2L, 7L, 1L, 8L), c(1L, 9L, 4L, 8L, 7L, 3L, 5L,
2L), c(4L, 2L, 1L))), list(list(c(7L, 14L, 15L, 4L, 3L),
c(10L, 12L, 6L, 1L)), list(c(5L, 8L, 1
8 matches
Mail list logo