[R] lappy and xts get all indexes from a list ?

Joshua Ulrich josh.m.ulrich at gmail.com
Fri Oct 31 18:25:37 CET 2014


I do this a few times in the blotter package.  Try:
Dates <- unique(do.call(c,c(lapply(foo, index), use.names=FALSE,
recursive=FALSE)))


On Fri, Oct 31, 2014 at 11:44 AM, ce <zadig_1 at excite.com> wrote:
> Dear all,
>
> I have a list , and I want to get all indexes ( dates ) of xts objects  in one list:
>
> foo<-list(A = xts(seq(2),seq(Sys.Date(),Sys.Date()+2,length.out=2)), B = xts(seq(1),seq(Sys.Date()-2,Sys.Date()-1,length.out=1)) )
>
>> foo
> $A
>            [,1]
> 2014-10-31    1
> 2014-11-02    2
>
> $B
>            [,1]
> 2014-10-29    1
>
> lapply(foo, function(x) index(x))      gives A and B values separately . I want to get one list like :
>
> "2014-10-31" "2014-11-02" "2014-10-29"
>
> Thanks a lot.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
Joshua Ulrich  |  about.me/joshuaulrich
FOSS Trading  |  www.fosstrading.com



More information about the R-help mailing list