Hi Gabor, This is great, thanks. It brought the time down to about 4 seconds. The command do.call("merge.xts",L) also works in this case. Suppose that instead of the default "outer" join I wanted to use, say, a "left" join. Is that possible? I tried a few ways of adding the join="left" parameter to the do.call() command but I could not get the syntax to work (assuming it's even possible). Thanks, Eric On Thu, Jan 2, 2020 at 3:23 PM Gabor Grothendieck <ggrothendieck at gmail.com> wrote:> You don't need Reduce as xts already supports mutliway merges. This > perfroms one > multiway merge rather than k-1 two way merges. > > do.call("merge", L) > > On Thu, Jan 2, 2020 at 6:13 AM Eric Berger <ericjberger at gmail.com> wrote: > > > > Hi, > > I have a list L of about 2,600 xts's. > > Each xts has a single numeric column. About 90% of the xts's have > > approximately 500 rows, and the rest have fewer than 500 rows. > > I create a single xts using the command > > > > myXts <- Reduce( merge.xts, L ) > > > > By default, merge.xts() does an outer join (which is what I want). > > > > The command takes about 80 seconds to complete. > > I have plenty of RAM on my computer. > > > > Are there faster ways to accomplish this task? > > > > Thanks, > > Eric > > > > [[alternative HTML version deleted]] > > > > ______________________________________________ > > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > > 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. > > > > -- > Statistics & Software Consulting > GKX Group, GKX Associates Inc. > tel: 1-877-GKX-GROUP > email: ggrothendieck at gmail.com >[[alternative HTML version deleted]]
It is not clear what multiway left join means but merge.zoo (though not merge.xts) supports a generalized all= argument which is a logical vector having the same length as L that can be TRUE or FALSE for each object merged. The objects corresponding to TRUE will have all their times included in the result but the ones with FALSE will only be included if they correspond to an already existing time. merge.zoo is R based whereas merge.xts is C based so I would not expect it to be as fast although it is more powerful. If All is the logical vector having the same length as L then: Lzoo <- lapply(L, as.zoo) do.call("merge", c(Lzoo, list(all = All)) On Thu, Jan 2, 2020 at 9:31 AM Eric Berger <ericjberger at gmail.com> wrote:> > Hi Gabor, > This is great, thanks. It brought the time down to about 4 seconds. > The command > do.call("merge.xts",L) > also works in this case. > Suppose that instead of the default "outer" join I wanted to use, say, a "left" join. > Is that possible? I tried a few ways of adding the > join="left" > parameter to the do.call() command but I could not get the syntax to work (assuming it's even possible). > > Thanks, > Eric > > > On Thu, Jan 2, 2020 at 3:23 PM Gabor Grothendieck <ggrothendieck at gmail.com> wrote: >> >> You don't need Reduce as xts already supports mutliway merges. This >> perfroms one >> multiway merge rather than k-1 two way merges. >> >> do.call("merge", L) >> >> On Thu, Jan 2, 2020 at 6:13 AM Eric Berger <ericjberger at gmail.com> wrote: >> > >> > Hi, >> > I have a list L of about 2,600 xts's. >> > Each xts has a single numeric column. About 90% of the xts's have >> > approximately 500 rows, and the rest have fewer than 500 rows. >> > I create a single xts using the command >> > >> > myXts <- Reduce( merge.xts, L ) >> > >> > By default, merge.xts() does an outer join (which is what I want). >> > >> > The command takes about 80 seconds to complete. >> > I have plenty of RAM on my computer. >> > >> > Are there faster ways to accomplish this task? >> > >> > Thanks, >> > Eric >> > >> > [[alternative HTML version deleted]] >> > >> > ______________________________________________ >> > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> > 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. >> >> >> >> -- >> Statistics & Software Consulting >> GKX Group, GKX Associates Inc. >> tel: 1-877-GKX-GROUP >> email: ggrothendieck at gmail.com-- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com
> It is not clear what multiway left join means but merge.zoo (though > not merge.xts) supports a generalized all= argument which is a logical > vector having the same length as L that can be TRUE or FALSE for each > object merged. The objects corresponding to TRUE will have all their > times included in the result but the ones with FALSE will only be > included if they correspond to an already existing time. merge.zoo is > R based whereas merge.xts is C based so I would not expect it to be as > fast although it is more powerful. > > If All is the logical vector having the same length as L then: > > Lzoo <- lapply(L, as.zoo) > do.call("merge", c(Lzoo, list(all = All)) > > On Thu, Jan 2, 2020 at 9:31 AM Eric Berger <ericjberger at gmail.com> wrote: > > > > Hi Gabor, > > This is great, thanks. It brought the time down to about 4 seconds. > > The command > > do.call("merge.xts",L) > > also works in this case. > > Suppose that instead of the default "outer" join I wanted to use, say, a "left" join. > > Is that possible? I tried a few ways of adding the > > join="left" > > parameter to the do.call() command but I could not get the syntax to work (assuming it's even possible). > > > > Thanks, > > Eric > > > > > > On Thu, Jan 2, 2020 at 3:23 PM Gabor Grothendieck <ggrothendieck at gmail.com> wrote: > >> > >> You don't need Reduce as xts already supports mutliway merges. This > >> perfroms one > >> multiway merge rather than k-1 two way merges. > >> > >> do.call("merge", L) > >> > >> On Thu, Jan 2, 2020 at 6:13 AM Eric Berger <ericjberger at gmail.com> wrote: > >> > > >> > Hi, > >> > I have a list L of about 2,600 xts's. > >> > Each xts has a single numeric column. About 90% of the xts's have > >> > approximately 500 rows, and the rest have fewer than 500 rows. > >> > I create a single xts using the command > >> > > >> > myXts <- Reduce( merge.xts, L ) > >> > > >> > By default, merge.xts() does an outer join (which is what I want). > >> > > >> > The command takes about 80 seconds to complete. > >> > I have plenty of RAM on my computer. > >> > > >> > Are there faster ways to accomplish this task? > >> > > >> > Thanks, > >> > Eric > >> > > >> > [[alternative HTML version deleted]] > >> > > >> > ______________________________________________ > >> > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > >> > 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. > >> > >> > >> > >> -- > >> Statistics & Software Consulting > >> GKX Group, GKX Associates Inc. > >> tel: 1-877-GKX-GROUP > >> email: ggrothendieck at gmail.com > > > > -- > Statistics & Software Consulting > GKX Group, GKX Associates Inc. > tel: 1-877-GKX-GROUP > email: ggrothendieck at gmail.com-- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com
On 02/01/2020 9:31 a.m., Eric Berger wrote:> Hi Gabor, > This is great, thanks. It brought the time down to about 4 seconds. > The command > do.call("merge.xts",L) > also works in this case. > Suppose that instead of the default "outer" join I wanted to use, say, a > "left" join. > Is that possible? I tried a few ways of adding the > join="left" > parameter to the do.call() command but I could not get the syntax to work > (assuming it's even possible).This should work: do.call("merge", c(L, join = "left")) The second argument to do.call is a list which becomes the arguments to the function being called. Your time series should be unnamed entries in the list, while other arguments to merge() should be named. Duncan Murdoch> > Thanks, > Eric > > > On Thu, Jan 2, 2020 at 3:23 PM Gabor Grothendieck <ggrothendieck at gmail.com> > wrote: > >> You don't need Reduce as xts already supports mutliway merges. This >> perfroms one >> multiway merge rather than k-1 two way merges. >> >> do.call("merge", L) >> >> On Thu, Jan 2, 2020 at 6:13 AM Eric Berger <ericjberger at gmail.com> wrote: >>> >>> Hi, >>> I have a list L of about 2,600 xts's. >>> Each xts has a single numeric column. About 90% of the xts's have >>> approximately 500 rows, and the rest have fewer than 500 rows. >>> I create a single xts using the command >>> >>> myXts <- Reduce( merge.xts, L ) >>> >>> By default, merge.xts() does an outer join (which is what I want). >>> >>> The command takes about 80 seconds to complete. >>> I have plenty of RAM on my computer. >>> >>> Are there faster ways to accomplish this task? >>> >>> Thanks, >>> Eric >>> >>> [[alternative HTML version deleted]] >>> >>> ______________________________________________ >>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >>> 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. >> >> >> >> -- >> Statistics & Software Consulting >> GKX Group, GKX Associates Inc. >> tel: 1-877-GKX-GROUP >> email: ggrothendieck at gmail.com >> > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. >
join = "left" only applies with merge.xts if there are two objects. If there are more it acts the same as join = TRUE.. See the Details section of ?merge.xts On Thu, Jan 2, 2020 at 1:29 PM Duncan Murdoch <murdoch.duncan at gmail.com> wrote:> > On 02/01/2020 9:31 a.m., Eric Berger wrote: > > Hi Gabor, > > This is great, thanks. It brought the time down to about 4 seconds. > > The command > > do.call("merge.xts",L) > > also works in this case. > > Suppose that instead of the default "outer" join I wanted to use, say, a > > "left" join. > > Is that possible? I tried a few ways of adding the > > join="left" > > parameter to the do.call() command but I could not get the syntax to work > > (assuming it's even possible). > > This should work: > > do.call("merge", c(L, join = "left")) > > The second argument to do.call is a list which becomes the arguments to > the function being called. Your time series should be unnamed entries > in the list, while other arguments to merge() should be named. > > Duncan Murdoch > > > > > Thanks, > > Eric > > > > > > On Thu, Jan 2, 2020 at 3:23 PM Gabor Grothendieck <ggrothendieck at gmail.com> > > wrote: > > > >> You don't need Reduce as xts already supports mutliway merges. This > >> perfroms one > >> multiway merge rather than k-1 two way merges. > >> > >> do.call("merge", L) > >> > >> On Thu, Jan 2, 2020 at 6:13 AM Eric Berger <ericjberger at gmail.com> wrote: > >>> > >>> Hi, > >>> I have a list L of about 2,600 xts's. > >>> Each xts has a single numeric column. About 90% of the xts's have > >>> approximately 500 rows, and the rest have fewer than 500 rows. > >>> I create a single xts using the command > >>> > >>> myXts <- Reduce( merge.xts, L ) > >>> > >>> By default, merge.xts() does an outer join (which is what I want). > >>> > >>> The command takes about 80 seconds to complete. > >>> I have plenty of RAM on my computer. > >>> > >>> Are there faster ways to accomplish this task? > >>> > >>> Thanks, > >>> Eric > >>> > >>> [[alternative HTML version deleted]] > >>> > >>> ______________________________________________ > >>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > >>> 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. > >> > >> > >> > >> -- > >> Statistics & Software Consulting > >> GKX Group, GKX Associates Inc. > >> tel: 1-877-GKX-GROUP > >> email: ggrothendieck at gmail.com > >> > > > > [[alternative HTML version deleted]] > > > > ______________________________________________ > > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > > 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. > > >-- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com