as_data_frame {tibble} | R Documentation |
as.data.frame
is effectively a thin wrapper around data.frame
,
and hence is rather slow (because it calls data.frame
on each element
before cbind
ing together). as_data_frame
is a new S3 generic
with more efficient methods for matrices and data frames.
as_data_frame(x, ...) ## S3 method for class 'tbl_df' as_data_frame(x, ...) ## S3 method for class 'data.frame' as_data_frame(x, ...) ## S3 method for class 'list' as_data_frame(x, validate = TRUE, ...) ## S3 method for class 'matrix' as_data_frame(x, ...) ## S3 method for class 'table' as_data_frame(x, n = "n", ...) ## S3 method for class 'NULL' as_data_frame(x, ...)
x |
A list. Each element of the list must have the same length. |
... |
Other arguments passed on to individual methods. |
validate |
When |
n |
Name for count column, default: |
This is an S3 generic. tibble includes methods for data frames (adds tbl_df classes), tbl_dfs (trivial!), lists, matrices, and tables.
l <- list(x = 1:500, y = runif(500), z = 500:1) df <- as_data_frame(l) m <- matrix(rnorm(50), ncol = 5) colnames(m) <- c("a", "b", "c", "d", "e") df <- as_data_frame(m) # as_data_frame is considerably simpler than as.data.frame # making it more suitable for use when you have things that are # lists ## Not run: l2 <- replicate(26, sample(letters), simplify = FALSE) names(l2) <- letters microbenchmark::microbenchmark( as_data_frame(l2, validate = FALSE), as_data_frame(l2), as.data.frame(l2) ) m <- matrix(runif(26 * 100), ncol = 26) colnames(m) <- letters microbenchmark::microbenchmark( as_data_frame(m), as.data.frame(m) ) ## End(Not run)