#' Read mean trait data
#'
#' This function is a wrapper around \code{read_data} tailored at reading the
#' output file "traitmeans.dat" into a tibble with one row per deme and per patch
#' and one column per trait.
#'
#' @param root Path to the simulation folder
#'
#' @return A tibble
#'
#' @seealso \code{read_data}
#'
#' @examples
#'
#' root <- system.file("extdata", "sim-example", package = "brachypoder")
#' read_trait_mean_data(root)
#'
#'@export
read_trait_mean_data <- function(root) {
pars <- read_parameters(root)
ndemes <- length(pars$pgood) - 1
# Read the data and split them into the corresponding columns
data <- read_data(root, variables = "traitmeans", ncols = 1)
data$patch <- rep(0:1, nrow(data) / 2)
ntimepoints <- nrow(data) / (ndemes * 2)
data$deme <- rep(rep(seq(ndemes), each = 2), ntimepoints)
# Read time points
timepoints <- read_binary(paste0(root, "/time.dat"))
data$time <- rep(timepoints, each = ndemes * 2)
# Reorder columns
data <- data[, c(4, 3, 2, 1)]
# Rename the columns
names(data) <- c("time", "deme", "patch", "x")
return(data)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.