merge.xts {xts}R Documentation

Merge xts Objects

Description

Perform merge operations on xts objects by time index.

Usage

## S3 method for class 'xts'
merge(
  ...,
  all = TRUE,
  fill = NA,
  suffixes = NULL,
  join = "outer",
  retside = TRUE,
  retclass = "xts",
  tzone = NULL,
  drop = NULL,
  check.names = NULL
)

## S3 method for class 'xts'
cbind(..., all = TRUE, fill = NA, suffixes = NULL)

Arguments

...

One or more xts objects, or objects coercible to class xts.

all

A logical vector indicating merge type.

fill

Values to be used for missing elements.

suffixes

Suffix to be added to merged column names.

join

Type of database join. One of 'outer', 'inner', 'left', or 'right'.

retside

Which side of the merged object should be returned (2-case only)?

retclass

Either a logical value indicating whether the result should have a 'class' attribute, or the name of the desired class for the result.

tzone

Time zone to use for the merged result.

drop

Not currently used.

check.names

Use make.names() to ensure column names are vaild R object names?

Details

This xts method is compatible with merge.zoo() but implemented almost entirely in C-level code for efficiency.

The function can perform all common database join operations along the time index by setting 'join' to one of the values below. Note that 'left' and 'right' are only implemented for two objects.

The above join types can also be accomplished by setting 'all' to one of the values below.

The result will have the timezone of the leftmost argument if available. Use the 'tzone' argument to override the default behavior.

When retclass = NULL the joined objects will be split and reassigned silently back to the original environment they are called from. This is for backward compatibility with zoo, but unused by xts. When retclass = FALSE the object will be stripped of its class attribute. This is for internal use.

See the examples in order to join using an 'all' argument that is the same arguments to join, like you can do with merge.zoo().

Value

A new xts object containing the appropriate elements of the objects passed in to be merged.

Note

This is a highly optimized merge, specifically designed for ordered data. The only supported merging is based on the underlying time index.

Author(s)

Jeffrey A. Ryan

References

Merge Join Discussion: https://blogs.msdn.microsoft.com/craigfr/2006/08/03/merge-join/

Examples


(x <- xts(4:10, Sys.Date()+4:10))
(y <- xts(1:6, Sys.Date()+1:6))

merge(x,y)
merge(x,y, join='inner')
merge(x,y, join='left')
merge(x,y, join='right')

merge.zoo(zoo(x),zoo(y),zoo(x), all=c(TRUE, FALSE, TRUE))
merge(merge(x,x),y,join='left')[,c(1,3,2)]

# zero-width objects (only index values) can be used
xi <- xts( , index(x))
merge(y, xi)


[Package xts version 0.14.0 Index]