[R] check a list that a sublist exists

Alaios alaios at yahoo.com
Tue Mar 3 11:03:11 CET 2015


Hi all,I have a list that has the following fields.
$`80`
[1] "Error in if (fitcass1[[2]] == \"Error\") { : \n  Fehlender Wert, wo TRUE/FALSE nötig ist\n"
attr(,"class")
[1] "try-error"
attr(,"condition")
<simpleError in if (fitcass1[[2]] == "Error") {    print(sprintf("error at fitting gamma distribution with %s periods. Mean %f %f Sd %f %f",         flag, mean1, mean2, sd1, sd2))} else {    return(fitcass1)}: Fehlender Wert, wo TRUE/FALSE nötig ist>


$`81`
[1] 0

$`9`
[1] 0

$`79`
$parameters
            pi           mu    sigma
1 0.9996796725     1.654832 127.6542
2 0.0003203275 17183.001125 302.8063

$se
         pi.se      mu.se sigma.se
1 2.113882e-05  0.1439152 14.22274
2 2.113882e-05 38.3582148      NaN

$distribution
[1] "gamma"



and so one. The content of each first level sublist are never the same. I want for each first-level sublist my list has to check fast that the current element , lets say the 79th has the $parameters.then I would keep only the numbers from the sublists that have this $parameters inside them and skip all the rest.
I tried something like exists(Mylist[[i]]$parameters) but it does not workI also tried the is.numeric(Mylist[[i]]$parameters)) but this line fails when the current sublist does not contain the $parameters field.
Can you please help me sort this out?
RegardsAlex


	[[alternative HTML version deleted]]



More information about the R-help mailing list