SCM

SCM Repository

[twsinstrument] View of /pkg/qmao/R/do.call.rbind.R
ViewVC logotype

View of /pkg/qmao/R/do.call.rbind.R

Parent Directory Parent Directory | Revision Log Revision Log


Revision 291 - (download) (annotate)
Mon Jun 25 15:19:30 2012 UTC (2 years ago) by gsee
File size: 964 byte(s)
Move some functions from (private) package:gsee
 - getHoldings.vaneck (get holdings of Van Eck ETFs; e.g. GLD, OIH)
 - getHoldings.powershares (getHoldings of PowerShares (e.g. QQQ)
 - getSymbols.pos (a getSymbols method to get data from an environment; not terribly useful, and not exported)
 - MakeStrictlyRegular (missing data? na.locf until you have the right number of rows for each day)
 - ExcludeTimes (remove a timespan from multiple days of data)
 - ExcludeDates (remove one or more days worth of data)
 - do.call.rbind (faster, less memory intensive way to do.call(rbind, *))
#' Faster way to \code{do.call(rbind, lst)}
#' 
#' This is a functionalized version of Dominik's answer here: 
#' \url{http://stackoverflow.com/questions/7224938/can-i-rbind-be-parallelized-in-r}
#' it does what do.call(rbind, lst) would do, but faster and with less memory usage
#'
#' @param lst a list to be rbound. (No guaranteed this funtion will offer an improvement unless
#' \code{lst} is a lits of xts objects)
#' @references \url{http://stackoverflow.com/questions/7224938/can-i-rbind-be-parallelized-in-r}
#' @examples
#' x <- xts(rnorm(10000), Sys.time()-10000:1*60)
#' splx <- split(x, 'days')
#' dcrx <- do.call.rbind(splx)
#' identical(x, dcrx)
#' @export
do.call.rbind <- function(lst) {
    while(length(lst) > 1) {
        idxlst <- seq(from=1, to=length(lst), by=2)

        lst <- lapply(idxlst, function(i) {
            if(i==length(lst)) { return(lst[[i]]) }

            return(rbind(lst[[i]], lst[[i+1]]))
        })
    }
    lst[[1]]
}



R-Forge@R-project.org
ViewVC Help
Powered by ViewVC 1.0.0  
Thanks to:
Vienna University of Economics and Business University of Wisconsin - Madison Powered By FusionForge