[R] data frame returned from sapply but vector expected

PIKAL Petr petr@p|k@| @end|ng |rom prechez@@cz
Fri Nov 4 13:57:04 CET 2022

Hallo Ivan

Thanks, yes it seems to be working. I thought also removing NULL by

mylist2[sapply(mylist2, is.null)] <- NULL

but your approach is probably better (in any case simpler)

Thanks again.


> -----Original Message-----
> From: Ivan Krylov <krylov.r00t using gmail.com>
> Sent: Friday, November 4, 2022 1:37 PM
> To: PIKAL Petr <petr.pikal using precheza.cz>
> Cc: R-help Mailing List <r-help using r-project.org>
> Subject: Re: [R] data frame returned from sapply but vector expected
> On Fri, 4 Nov 2022 15:30:27 +0300
> Ivan Krylov <krylov.r00t using gmail.com> wrote:
> > sapply(mylist2, `[[`, 'b')
> Wait, that would simplify the return value into a matrix when there are no
> NULLs. But lapply(mylist2, `[[`, 'b') should work in both cases, which in
> opinion goes to show the dangers of using simplifying functions in
> code.
> Sorry for the double-post!
> --
> Best regards,
> Ivan

More information about the R-help mailing list