[R] [R-SIG-Finance] getting a subset corresponding to a list element
rharlow86 at gmail.com
Fri May 26 23:12:55 CEST 2017
Try not to post twice - this is really more of a general R question. To
answer the question, however, turn each element of your resultlist into an
xts (or zoo) object so that you have a list of xts objects (called xtsList
for example.) Then call do.call("merge", xtsList). Also, your example is
tough because it requires access to bloomberg, which isn't necessarily the
case for the vast majority of R users.
On Fri, May 26, 2017 at 4:58 PM, Michael Ashton <
m.ashton at enduringinvestments.com> wrote:
> I'm not sure how to ask this with the proper terminology, but here goes:
> The BDH() function in RBLPAPI returns, for a list of symbols (e.g., 'SPX
> Index','RIY Index','IBM Equity') a list of closing prices. The problem is
> that the result is not a matrix or a dataframe, but a list.
> So, if I run the query with 3 symbols, I get a list with 3 elements. For
> example, in this case, if
> symbolist <-c("SPX Index","MXWO Index","MXEA Index")
> resultlist <- bdh(symbollist, "PX_LAST", options=opt,start.date=as.
> then resultlist is a list with 3 elements, and as many rows as there are
> dates between "begdate" and today (or as many month-ends, if "opt" declares
> monthly periodicity). Suppose in this case I've set this up to retrieve 60
> But I don't WANT a list. I want a zoo object containing each of these as
> an element. I thought about starting by trying to put each element in a
> matrix by
> and then looping through from 1 to length(symbolist), letting
> data[,i] <- resultlist$symbollist[i][,2]
> but this clearly doesn't work since what I really want is
> data[,1] <-resultlist$'SPX Index'[,2]
> data[,2] <-resultlist$'MXWO Index'[,2]
> But there's probably a much easier way to do this.
> I am sending this to both the general help list and the r-sig-finance list
> since there is probably both a general way to stuff a list into a zoo
> object and a way to do it cleanly with the BDH() command. Thanks in advance
> for help.
> [[alternative HTML version deleted]]
> R-SIG-Finance at r-project.org mailing list
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions
> should go.
[[alternative HTML version deleted]]
More information about the R-help