[R] Select components of a list

arun smartpink111 at yahoo.com
Sun Feb 17 16:26:26 CET 2013


Sorry, I just noticed that in the first line of the solution 'l' got stripped off, it should be read as 'lapply` instead of 'apply`.

lapply(1:length(models),function(i) lapply(models[[i]],function(x) summary(x)$p.table[2,]))[[1]] #1st list component
Thanks,

A.K.





________________________________
From: Gustav Sigtuna <gsigtuna at gmail.com>
To: arun <smartpink111 at yahoo.com> 
Sent: Sunday, February 17, 2013 5:49 AM
Subject: Re: Select components of a list


Dear Arun,

Thanks again. The script works perfectly for GLM. Strangely, it does not work for GAM, although it has the same output for the linear part. I cannot figure out the error message. I have attached the gam code and  error message .

Thanks




On Sun, Feb 17, 2013 at 3:11 AM, arun <smartpink111 at yahoo.com> wrote:

HI Gustav,
>
>If you need the combined output:
>res<-lapply(1:length(models),function(i) do.call(rbind,lapply(models[[i]],function(x) summary(x)$coef[row.names(summary(x)$coef)%in%c("pm10","ozone","so2"),c(1:2,4)])))
> names(res)<-1:length(res)
>res1<-do.call(rbind,lapply(res,function(i) {row.names(i)<-c("pm10","ozone","so2");data.frame(i)}))
>names(res1)[2:3]<- c("Std.Error","Pr(>|z|)")
>res1
>#            Estimate    Std.Error     Pr(>|z|)
>#1.pm10  0.0005999185 0.0001486195 5.423004e-05
>#1.ozone 0.0010117294 0.0003792739 7.640816e-03
>#1.so2   0.0026595441 0.0009352046 4.457766e-03
>#2.pm10  0.0005720549 0.0001740368 1.012696e-03
>#2.ozone 0.0009128304 0.0004364390 3.647954e-02
>#2.so2   0.0028256121 0.0010150314 5.373144e-03
>#3.pm10  0.0005099552 0.0001559620 1.076462e-03
>#3.ozone 0.0023896044 0.0004109854 6.087769e-09
>#3.so2   0.0024097381 0.0009563814 1.174744e-02
>#4.pm10  0.0009285593 0.0001766520 1.468764e-07
>#4.ozone 0.0005455392 0.0004301502 2.047076e-01
>#4.so2   0.0017251400 0.0011635156 1.381552e-01
>A.K.
>
>
>
>
>
>
>
>________________________________
>From: Gustav Sigtuna <gsigtuna at gmail.com>
>
>To: arun <smartpink111 at yahoo.com>
>Sent: Saturday, February 16, 2013 7:44 PM
>
>Subject: Re: Select components of a list
>
>
>Hi Arun,
>
>Thanks for taking your time to find a solution.
>
>I have attached a R script that will recreate a comparable list from publicly available data. My list is longer and created by various models  than the one created here. However, the final output is similar to the one produced by script. My interest is to extract only the coefficients for  pm10., ozone and so2 (  Estimate,  Std. Error  and p value)    . 
>
>Thanks
>
>
>
>
>
>
>On Fri, Feb 15, 2013 at 9:04 PM, arun <smartpink111 at yahoo.com> wrote:
>
>Dear Gustav,
>>Thank you for the data.  Could you select a smaller subset of the list and dput() that subset?  Your data is useful, but I would have to recreate list of lists from that to test and sometimes that may not accurate represent the format in your list as it is the summary().
>>Arun
>>
>>
>>
>>
>>
>>
>>
>>________________________________
>>From: Gustav Sigtuna <gsigtuna at gmail.com>
>>To: smartpink111 at yahoo.com
>>Sent: Friday, February 15, 2013 4:56 AM
>>Subject: Re: Select components of a list
>>
>>
>>
>>Hi Arun,
>>
>>Thanks for your help. Your mail landed in my spam folder and just saw it by chance.
>>
>>I have attached a text file that contains the list of my model. It was extremely long, thus I took out the last part which is think is more important.
>>
>>
>>In brief I have an output from GAM model which resulted from analysis of  ozone at three time points on 12 data sets
>>
>>Thanks for your assistance
>>
>>
>>
>>
>>
>>On Wed, Feb 13, 2013 at 8:21 PM, <smartpink111 at yahoo.com> wrote:
>>
>>Dear Lungo,
>>>
>>>If you can email (smartpink111 at yahoo.com) me the `list` (dput(list)), I can take a look at it.  Probably, you understand that my previous solution was just guesswork. With regards to GLM, GAM, it is good to check the structure of the list (str()). It gives information about whether a `generic` tool could be applied to extract them or not.
>>>Cheers.
>>>Arun
>>>
>>><quote author='Lungo'>
>>>Dear Arun,  Your code and the example works fine. However my list is quite
>>>different from the one showed in your example.   As I have shown in my
>>>question above I have 12 lists each having 3 lists underneath.  I get the
>>>lists by different models (GLM, GAM ) but the output  I aim to have is the
>>>estimates of the explanatory variable which is placed next to the intercept.
>>>Thus I am looking for a “generic” tool that would extract these lists.
>>></quote>
>>>Quoted from:
>>>http://r.789695.n4.nabble.com/Select-components-of-a-list-tp4658295p4658389.html
>>> 
>>
>



More information about the R-help mailing list