EVOLUTION-MANAGER
Edit File: merge.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Merge xts Objects</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for merge.xts {xts}"><tr><td>merge.xts {xts}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2> Merge xts Objects </h2> <h3>Description</h3> <p>Used to perform merge operation on <code>xts</code> objects by <em>time</em> (index). Given the inherent ordered nature of <code>xts</code> time-series, a merge-join style merge allows for optimally efficient joins. </p> <h3>Usage</h3> <pre> ## 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) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>...</code></td> <td> <p> one or more xts objects, or objects coercible to class xts </p> </td></tr> <tr valign="top"><td><code>all</code></td> <td> <p> a logical vector indicating merge type </p> </td></tr> <tr valign="top"><td><code>fill</code></td> <td> <p> values to be used for missing elements </p> </td></tr> <tr valign="top"><td><code>suffixes</code></td> <td> <p> to be added to merged column names </p> </td></tr> <tr valign="top"><td><code>join</code></td> <td> <p> type of database join </p> </td></tr> <tr valign="top"><td><code>retside</code></td> <td> <p> which side of the merged object should be returned (2-case only) </p> </td></tr> <tr valign="top"><td><code>retclass</code></td> <td> <p> object to return </p> </td></tr> <tr valign="top"><td><code>tzone</code></td> <td> <p> time zone of merged object </p> </td></tr> <tr valign="top"><td><code>drop</code></td> <td> <p> not currently used </p> </td></tr> <tr valign="top"><td><code>check.names</code></td> <td> <p> not currently used </p> </td></tr> </table> <h3>Details</h3> <p>This is an xts method compatible with merge.zoo, as xts extends zoo. That documentation should also be referenced. Difference are noted where applicable. </p> <p>Implemented almost entirely in custom C-level code, it is possible using either the <code>all</code> argument or the <code>join</code> argument to implement all common database join operations along the to-be-merged objects time-index: ‘outer’ (full outer - all rows), ‘inner’ (only rows with common indexes), ‘left’ (all rows in the left object, and those that match in the right), and ‘right’ (all rows in the right object, and those that match in the left). </p> <p>The above join types can also be expressed as a vector of logical values passed to <code>all</code>. c(TRUE,TRUE) or TRUE for ‘join="outer"’, c(FALSE,FALSE) or FALSE for ‘join="inner"’, c(TRUE, FALSE) for ‘join="left"’, and c(FALSE,TRUE) for ‘join="right"’. </p> <p>Note that the <code>all</code> and <code>join</code> arguments imply a two case scenario. For merging more than two objects, they will simply fall back to a full outer or full inner join, depending on the first position of all, as left and right can be ambiguous with respect to sides. </p> <p>To do something along the lines of merge.zoo's method of joining based on an all argument of the same length of the arguments to join, see the example. </p> <p>The resultant object will have the timezone of the leftmost argument if available. Use <code>tzone</code> to override. </p> <p>If <code>retclass</code> is <code>NULL</code>, 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, though unused by xts. </p> <p>If <code>retclass</code> is <code>FALSE</code> the object will be stripped of its class attribute. This is for internal use. </p> <h3>Value</h3> <p>A new <code>xts</code> object containing the appropriate elements of the objects passed in to be merged. </p> <h3>Note</h3> <p>This is a highly optimized merge, specifically designed for ordered data. The only supported merging is based on the underlying time index. </p> <h3>Author(s)</h3> <p> Jeffrey A. Ryan </p> <h3>References</h3> <p> Merge Join Discussion: <a href="https://blogs.msdn.microsoft.com/craigfr/2006/08/03/merge-join/">https://blogs.msdn.microsoft.com/craigfr/2006/08/03/merge-join/</a> </p> <h3>Examples</h3> <pre> (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) </pre> <hr /><div style="text-align: center;">[Package <em>xts</em> version 0.12.2 <a href="00Index.html">Index</a>]</div> </body></html>