as_dataframe | R Documentation |
Convert an object into a dataframe
and check for it. A
dataframe
(without dot) is both a data.frame
(with dot, the default
rectangular dataset structure in R) and a tibble
, the tidyverse
equivalence. In fact, dataframe
s behave almost completely like a tibble
,
except for a few details explained in the details section.
as_dataframe(x, ...)
as.dataframe(x, ...)
## Default S3 method:
as_dataframe(x, tz = "UTC", ...)
## S3 method for class 'data.frame'
as_dataframe(x, ..., rownames = "rownames")
## S3 method for class 'dataframe'
as_dataframe(
x,
...,
rownames = "rownames",
.name_repair = c("check_unique", "unique", "universal", "minimal")
)
## S3 method for class 'list'
as_dataframe(
x,
.name_repair = c("check_unique", "unique", "universal", "minimal"),
...
)
## S3 method for class 'matrix'
as_dataframe(x, ..., rownames = "rownames")
## S3 method for class 'table'
as_dataframe(x, n = "n", ...)
is_dataframe(x)
is.dataframe(x)
x |
An object to convert to a |
... |
Additional parameters. |
tz |
The time zone. Useful for converting |
rownames |
Name of the column that is prepended to the
|
.name_repair |
Treatment for problematic column names. |
n |
The name for the column containing the number of items, |
TODO: explain difference between dataframe
s and tibble
s here...
A dataframe
, which is an S3 object with class
c("dataframe", "tbl_df", "tbl", "data.frame")
.
Philippe Grosjean phgrosjean@sciviews.org
as_tibble()
, as.data.frame()
class(as.dataframe(mtcars))
class(as.dataframe(tibble::tribble(~x, ~y, 1, 2, 3, 4)))
# Any object, like a vector
v1 <- 1:10
is_dataframe(v1)
(df1 <- as_dataframe(v1))
is_dataframe(df1)
# Check names of an existing dataframe
(as_dataframe(df1, .name_repair = "universal"))
# A data.frame with trivial row names
datasets::iris
as_dataframe(datasets::iris)
# A data.frame containing meaningful row names
datasets::mtcars
as_dataframe(datasets::mtcars)
# A list
l1 <- list(x = 1:3, y = rnorm(3))
as_dataframe(l1)
# A matrix with column and row names
(m1 <- matrix(1:9, nrow = 3L, dimnames = list(letters[1:3], LETTERS[1:3])))
as_dataframe(m1)
# A table
set.seed(756)
(t1 <- table(sample(letters[1:5], 50, replace = TRUE)))
as_dataframe(t1)
# compare with the base R function:
as.data.frame(t1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.