Hallo all
I found a strange problem for coding if part of list is NULL.
In this case, sapply result is ***list of data frames*** but if there is no
NULL leaf, the result is ***list of vectors***.
I tried simplify option but it did not help me neither I found anything in
help page.
The code is part of bigger project where I fill list by reading in data and
if it fails, the leaf is set to NULL. Then the the boxplot is created simply
by
boxplot(sapply(mylist2, "[", "b")) and the user is asked to
select if values
should be rbinded or not.
Is it possible to perform some *apply without getting data frame as result
in case NULL leaf?
Here is an example (without boxplot)
df1 <- data.frame(a=rnorm(5), b=runif(5), c=rlnorm(5))
df2 <- data.frame(a=rnorm(5), b=runif(5), c=rlnorm(5))
mylist1 <- list(df1,df2, df3)
mylist2 <- list(NULL,df2, df3)
> str(sapply(mylist1, "[", "b"))
List of 3
$ b: num [1:5] 0.387 0.69 0.876 0.836 0.819
$ b: num [1:5] 0.01733 0.46055 0.19421 0.11609 0.00789
$ b: num [1:5] 0.593 0.478 0.299 0.185 0.847
> str(sapply(mylist2, "[", "b"))
List of 3
$ : NULL
$ :'data.frame': 5 obs. of 1 variable:
..$ b: num [1:5] 0.01733 0.46055 0.19421 0.11609 0.00789
$ :'data.frame': 5 obs. of 1 variable:
..$ b: num [1:5] 0.593 0.478 0.299 0.185 0.847
S pozdravem | Best Regards
RNDr. Petr PIKAL
Vedouc? V?zkumu a v?voje | Research Manager
PRECHEZA a.s.
n?b?. Dr. Edvarda Bene?e 1170/24 | 750 02 P?erov | Czech Republic
Tel: +420 581 252 256 | GSM: +420 724 008 364
<mailto:petr.pikal at precheza.cz> petr.pikal at precheza.cz |
<https://www.precheza.cz/> www.precheza.cz
Osobn? ?daje: Informace o zpracov?n? a ochran? osobn?ch ?daj? obchodn?ch
partner? PRECHEZA a.s. jsou zve?ejn?ny na:
<https://www.precheza.cz/zasady-ochrany-osobnich-udaju/>
https://www.precheza.cz/zasady-ochrany-osobnich-udaju/ | Information about
processing and protection of business partner's personal data are available
on website:
<https://www.precheza.cz/en/personal-data-protection-principles/>
https://www.precheza.cz/en/personal-data-protection-principles/
D?v?rnost: Tento e-mail a jak?koliv k n?mu p?ipojen? dokumenty jsou d?v?rn?
a podl?haj? tomuto pr?vn? z?vazn?mu prohl??en? o vylou?en? odpov?dnosti:
<https://www.precheza.cz/01-dovetek/> https://www.precheza.cz/01-dovetek/
|
This email and any documents attached to it may be confidential and are
subject to the legally binding disclaimer:
<https://www.precheza.cz/en/01-disclaimer/>
https://www.precheza.cz/en/01-disclaimer/