[R] how to extract from list

Rui Barradas ruipbarradas at sapo.pt
Tue Oct 16 17:40:25 CEST 2012


Hello,

Inline.
Em 16-10-2012 16:22, Balqis escreveu:
> well that function is the one I created, manipulating pargev from evir
> package. maybe this is where I have to check I presume.

Maybe yes, we can't tell.

>
> for the 50k,the more the robust perhaps?

Yes, the more the merrier but if you want to be able to extract a 
certain vector element from each vector in a list then a small data 
example would do, and both Arun and I have already given answers to 
that. Both answers are equivalent, by the way. They use the extractor 
functions `[` and (mine) `[[`. In the particular case of vectors the 
results are exactly the same.

Rui Barradas

>
> On Tue, Oct 16, 2012 at 3:09 PM, Rui Barradas <ruipbarradas at sapo.pt> wrote:
>
>> Hello,
>>
>> Your code doesn't work, which libraries are you using? There are several
>> with function rgev.
>> And pargevn() also doesn't exist. Nor does the matrix/df inP.
>>
>> (And, for reproducible example there's no need to replicate 50K times...)
>>
>> Rui Barradas
>> Em 16-10-2012 13:41, Balqis escreveu:
>>
>>   Ok here's the lines of codes:
>>> sIr=replicate(50000,ts(arima.**sim(list(ar=0),n=150,innov=**
>>> rgev(150,xi=0.2,
>>> mu=inP[1,5],sigma=inP[1,4]),**start.innov=rgev(150,xi=0.2,
>>> mu=inP[1,5],sigma=inP[1,4]))))
>>>
>>> sIrr=data.frame(cbind(sIr))
>>>
>>> EsIpr=sapply(sIrr[1:100,1:**20000],function(m) pargevn(lmom.ub(m)))
>>>
>>> kIpr=EsIpr[3,]#try to call for kappa
>>> Error in EsIpr[3, ] : incorrect number of dimensions
>>>
>>> #it turn out that the Eslpr is a list. It is kinda weird because
>>> previously
>>> I run the same routine for
>>>
>>> Eslr=sapply(sIrr[1:150,20000])**, function (m) pargevn(lmom.ub(m))# it
>>> works
>>> out fine when I call
>>> kI=EsIr[3,]
>>>
>>> Thanks!
>>>
>>>
>>> On Tue, Oct 16, 2012 at 12:35 PM, Muhammad Rahiz
>>> <muhammad.rahiz at gmail.com>**wrote:
>>>
>>>   Maybe something along the following lines?
>>>> m <- rep(list(rnorm(10)),3) # dummy data
>>>>
>>>> data <- c()
>>>> for (a in 1:length(m)) {
>>>> data[a] <- m[[a]][1] }
>>>>
>>>> Muhammad
>>>>
>>>>
>>>> On Tue, Oct 16, 2012 at 1:17 PM, Balqis <aehan3616 at gmail.com> wrote:
>>>>
>>>>   Hi all,
>>>>> I have a list of 20000 data, and the list look like below. I wonder what
>>>>> is
>>>>> the simplest way to extract 'kappa' value (or 'xi' or 'alpha' for the
>>>>> matter)  from each of the data. How can I simply code it without having
>>>>> to
>>>>> change the list to a dataframe first? Many thanks!
>>>>>
>>>>>
>>>>> $X19997
>>>>>            xi       alpha       kappa
>>>>> 784.7718640 165.4065141  -0.2709599
>>>>>
>>>>> $X19998
>>>>>            xi       alpha       kappa
>>>>> 860.7832604 215.1144980  -0.1769741
>>>>>
>>>>> $X19999
>>>>>            xi       alpha       kappa
>>>>> 839.7692675 196.0103874  -0.3848809
>>>>>
>>>>> $X20000
>>>>>            xi       alpha       kappa
>>>>> 847.6117040 212.3279185  -0.2576029
>>>>>
>>>>> regards,
>>>>> aehan
>>>>>
>>>>>           [[alternative HTML version deleted]]
>>>>>
>>>>> ______________________________**________________
>>>>> R-help at r-project.org mailing list
>>>>> https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help>
>>>>> PLEASE do read the posting guide
>>>>> http://www.R-project.org/**posting-guide.html<http://www.R-project.org/posting-guide.html>
>>>>> and provide commented, minimal, self-contained, reproducible code.
>>>>>
>>>>>
>>>> --
>>>> Muhammad Rahiz
>>>> (za) +27 071 719 0104
>>>> (skype) muhammad.rahiz
>>>>
>>>>
>>>>           [[alternative HTML version deleted]]
>>> ______________________________**________________
>>> R-help at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help>
>>> PLEASE do read the posting guide http://www.R-project.org/**
>>> posting-guide.html <http://www.R-project.org/posting-guide.html>
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>




More information about the R-help mailing list