benchmark/quickdf.r

library(microbenchmark)

quickdf1 <- function(list) {
  rows <- unique(unlist(lapply(list, NROW)))
  stopifnot(length(rows) == 1)

  names(list) <- make_names(list, "X")

  structure(list,
    class = "data.frame",
    row.names = seq_len(rows))
}

quickdf2 <- function(list) {
  rows <- unique(unlist(lapply(list, NROW)))
  stopifnot(length(rows) == 1)

  names(list) <- make_names(list, "X")
  class(list) <- "data.frame"
  attr(list, "row.names") <- c(NA_integer_, -rows)

  list
}

a <- list(a = 1:1e4, b = 1:1e4, c = 1:1e4)

microbenchmark(
  quickdf1(a),
  quickdf2(a))
hadley/plyr documentation built on Oct. 15, 2023, 8:20 a.m.