R/wide.R

Defines functions wide

Documented in wide

#' Wide Data Points Format
#'
#' Returns a \link[datapointsr]{long} dataset as wide format
#' @param df a \link[datapointsr]{long} format dataframe
#' @export

wide <- function(df){

  df <- data.table::as.data.table(df)
  len <- length(names(df)) - 2
  d <- stats::reshape(df,
                      timevar = "variable",
                      times = "value",
                      idvar = names(df)[1:len],
                      direction = "wide")
  names(d) <- stringr::str_replace_all(names(d), "value.", "")

  tibble::as_tibble(as.data.frame(d))

}
MattjCamp/datapointsr documentation built on Sept. 14, 2023, 12:43 p.m.