R/mergefromlists.R

#' Merge output from lists into matrices
#'
#' @param x is an object
#' @return y is the output
#' @export

mergefromlists <- function(list_layerForests, num_expForests,
                             n.train, n.test, n.testREAL){
  K <- length(list_layerForests)
  matrix_y.hat.train.final <- matrix(0, nrow = n.train, ncol = num_expForests*K)
  matrix_y.hat.test.final <- matrix(0, nrow = n.test, ncol = num_expForests*K)
  matrix_y.hat.testREAL.final <- matrix(0, nrow = n.testREAL, ncol = num_expForests*K)

  for (k in 1:K){
    matrix_y.hat.train.final[,((k-1)*num_expForests+1):(k*num_expForests)] <-list_layerForests[[k]][[1]]
    matrix_y.hat.test.final[,((k-1)*num_expForests+1):(k*num_expForests)] <-list_layerForests[[k]][[2]]
    matrix_y.hat.testREAL.final[,((k-1)*num_expForests+1):(k*num_expForests)] <-list_layerForests[[k]][[3]]
  }

  return(list(matrix_y.hat.train = matrix_y.hat.train.final, matrix_y.hat.test = matrix_y.hat.test.final, matrix_y.hat.testREAL = matrix_y.hat.testREAL.final))
}
thomaswiemann/SMLpractical documentation built on May 28, 2019, 12:23 p.m.