#' Align Index of Two Xts Objects
#'
#' @param ... parameters to pass to merge.xts
#'
#' @return list containing aligned xts objects
#' @export align.xts
#' @importFrom magrittr %>%
#' @import xts
#'
#' @examples align.xts(returns, weights, fill = NA, join = "outer")
#'
#'
align.xts <- function (...) {
mycall <- match.call()
mycall[[1]] <- as.symbol("merge.xts")
merged_xts <- eval(mycall, parent.frame())
n_xts <- list(...) %>% names() %in% "" %>% sum()
n_xts2 <- list(...) %>% length()
if(n_xts==0) {n_xts <- n_xts2}
n_cols <- eval(list(...)[[1]]) %>% ncol() %>% as.integer
colnames1 <- eval(list(...)[[1]]) %>% colnames()
xts_list <- split.default(as.data.frame(merged_xts),
rep(1:n_xts, each = n_cols))
xts_list %>% lapply(., function (x) {
x %>% 'colnames<-'(colnames1) %>%
as.xts(., dateFormat = "Date")
})
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.