as_dataframe: Deprecated! Convert objects into dataframes (subclassing...

View source: R/as_dataframe.R

as_dataframeR Documentation

Deprecated! Convert objects into dataframes (subclassing tibble) and check for it.

Description

[Deprecated]

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, dataframes behave almost completely like a tibble, except for a few details explained in the details section.

Usage

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)

Arguments

x

An object to convert to a dataframe.

...

Additional parameters.

tz

The time zone. Useful for converting ts objects with observations more frequent than daily.

rownames

Name of the column that is prepended to the dataframe with the original row names (dataframes and tibbles do not support row names). If NULL, row names are dropped. The inclusion of the rownames column is not done if row names are trivial, i.e., they equal the number of the rows in the data frame.

.name_repair

Treatment for problematic column names. "check.unique" (default value) do not repair names but make sure they are unique. "unique" make sure names are unique and non empty. "universal" make names unique and syntactic. "minimal"do not repair or check (just make sure names exist).

n

The name for the column containing the number of items, "n" by default.

Details

TODO: explain difference between dataframes and tibbles here...

Value

A dataframe, which is an S3 object with class c("dataframe", "tbl_df", "tbl", "data.frame").

Author(s)

Philippe Grosjean phgrosjean@sciviews.org

See Also

as_tibble(), as.data.frame()

Examples

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)


SciViews/data.io documentation built on May 5, 2024, 1:39 p.m.