#' given a list of stocks with data from bdh function, convert the list into a table
#' cl is the cluster created by doParallel , if this parameter is not given , the function will spawn the cluster itself
#' @export
bdhLongToWide <-function(bdhList, cl){
if( missing(cl)){
cl <- makeCluster(detectCores()-1)
registerDoParallel(cl)
}
combineDate = foreach(bdh = bdhList) %dopar% {
as.character( bdh$date)
}
combineDate = sort(as.Date(unique(unlist(combineDate)),format = "%Y-%m-%d"))
convertedBDH = foreach(bdh = bdhList) %dopar%{
output = rep(NA, length(combineDate))
names(output) = combineDate
output[as.character(bdh$date)] = bdh[,2]
output
}
result = do.call(cbind,convertedBDH)
colnames(result) =names(bdhList)
result
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.