EVOLUTION-MANAGER
Edit File: as_tibble.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Coerce lists, matrices, and more to data frames</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for as_tibble {tibble}"><tr><td>as_tibble {tibble}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Coerce lists, matrices, and more to data frames</h2> <h3>Description</h3> <p><code>as_tibble()</code> turns an existing object, such as a data frame or matrix, into a so-called tibble, a data frame with class <code><a href="tbl_df-class.html">tbl_df</a></code>. This is in contrast with <code><a href="tibble.html">tibble()</a></code>, which builds a tibble from individual columns. <code>as_tibble()</code> is to <code><a href="tibble.html">tibble()</a></code> as <code><a href="../../base/html/as.data.frame.html">base::as.data.frame()</a></code> is to <code><a href="../../base/html/data.frame.html">base::data.frame()</a></code>. </p> <p><code>as_tibble()</code> is an S3 generic, with methods for: </p> <ul> <li> <p><code><a href="../../base/html/data.frame.html">data.frame</a></code>: Thin wrapper around the <code>list</code> method that implements tibble's treatment of <a href="rownames.html">rownames</a>. </p> </li> <li> <p><code><a href="../../base/html/matrix.html">matrix</a></code>, <code><a href="../../stats/html/poly.html">poly</a></code>, <code><a href="../../stats/html/ts.html">ts</a></code>, <code><a href="../../base/html/table.html">table</a></code> </p> </li> <li><p> Default: Other inputs are first coerced with <code><a href="../../base/html/as.data.frame.html">base::as.data.frame()</a></code>. </p> </li></ul> <p><code>as_tibble_row()</code> converts a vector to a tibble with one row. If the input is a list, all elements must have size one. </p> <p><code>as_tibble_col()</code> converts a vector to a tibble with one column. </p> <h3>Usage</h3> <pre> as_tibble( x, ..., .rows = NULL, .name_repair = c("check_unique", "unique", "universal", "minimal"), rownames = pkgconfig::get_config("tibble::rownames", NULL) ) ## S3 method for class 'data.frame' as_tibble( x, validate = NULL, ..., .rows = NULL, .name_repair = c("check_unique", "unique", "universal", "minimal"), rownames = pkgconfig::get_config("tibble::rownames", NULL) ) ## S3 method for class 'list' as_tibble( x, validate = NULL, ..., .rows = NULL, .name_repair = c("check_unique", "unique", "universal", "minimal") ) ## S3 method for class 'matrix' as_tibble(x, ..., validate = NULL, .name_repair = NULL) ## S3 method for class 'table' as_tibble(x, `_n` = "n", ..., n = `_n`, .name_repair = "check_unique") ## S3 method for class ''NULL'' as_tibble(x, ...) ## Default S3 method: as_tibble(x, ...) as_tibble_row( x, .name_repair = c("check_unique", "unique", "universal", "minimal") ) as_tibble_col(x, column_name = "value") </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>A data frame, list, matrix, or other object that could reasonably be coerced to a tibble.</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>Unused, for extensibility.</p> </td></tr> <tr valign="top"><td><code>.rows</code></td> <td> <p>The number of rows, useful to create a 0-column tibble or just as an additional check.</p> </td></tr> <tr valign="top"><td><code>.name_repair</code></td> <td> <p>Treatment of problematic column names: </p> <ul> <li> <p><code>"minimal"</code>: No name repair or checks, beyond basic existence, </p> </li> <li> <p><code>"unique"</code>: Make sure names are unique and not empty, </p> </li> <li> <p><code>"check_unique"</code>: (default value), no name repair, but check they are <code>unique</code>, </p> </li> <li> <p><code>"universal"</code>: Make the names <code>unique</code> and syntactic </p> </li> <li><p> a function: apply custom name repair (e.g., <code>.name_repair = make.names</code> for names in the style of base R). </p> </li> <li><p> A purrr-style anonymous function, see <code><a href="../../rlang/html/as_function.html">rlang::as_function()</a></code> </p> </li></ul> <p>This argument is passed on as <code>repair</code> to <code><a href="../../vctrs/html/vec_as_names.html">vctrs::vec_as_names()</a></code>. See there for more details on these terms and the strategies used to enforce them.</p> </td></tr> <tr valign="top"><td><code>rownames</code></td> <td> <p>How to treat existing row names of a data frame or matrix: </p> <ul> <li> <p><code>NULL</code>: remove row names. This is the default. </p> </li> <li> <p><code>NA</code>: keep row names. </p> </li> <li><p> A string: the name of a new column. Existing rownames are transferred into this column and the <code>row.names</code> attribute is deleted. Read more in <a href="rownames.html">rownames</a>. </p> </li></ul> </td></tr> <tr valign="top"><td><code>_n, validate</code></td> <td> <p><a href="https://lifecycle.r-lib.org/articles/stages.html#soft-deprecated"><img src="../help/figures/lifecycle-soft-deprecated.svg" alt='[Soft-deprecated]' /></a> </p> <p>For compatibility only, do not use for new code.</p> </td></tr> <tr valign="top"><td><code>n</code></td> <td> <p>Name for count column, default: <code>"n"</code>.</p> </td></tr> <tr valign="top"><td><code>column_name</code></td> <td> <p>Name of the column.</p> </td></tr> </table> <h3>Row names</h3> <p>The default behavior is to silently remove row names. </p> <p>New code should explicitly convert row names to a new column using the <code>rownames</code> argument. </p> <p>For existing code that relies on the retention of row names, call <code>pkgconfig::set_config("tibble::rownames" = NA)</code> in your script or in your package's <code><a href="../../base/html/ns-hooks.html">.onLoad()</a></code> function. </p> <h3>Life cycle</h3> <p>Using <code>as_tibble()</code> for vectors is superseded as of version 3.0.0, prefer the more expressive <code>as_tibble_row()</code> and <code>as_tibble_col()</code> variants for new code. </p> <h3>See Also</h3> <p><code><a href="tibble.html">tibble()</a></code> constructs a tibble from individual columns. <code><a href="enframe.html">enframe()</a></code> converts a named vector to a tibble with a column of names and column of values. Name repair is implemented using <code><a href="../../vctrs/html/vec_as_names.html">vctrs::vec_as_names()</a></code>. </p> <h3>Examples</h3> <pre> m <- matrix(rnorm(50), ncol = 5) colnames(m) <- c("a", "b", "c", "d", "e") df <- as_tibble(m) as_tibble_row(c(a = 1, b = 2)) as_tibble_row(list(c = "three", d = list(4:5))) as_tibble_row(1:3, .name_repair = "unique") as_tibble_col(1:3) as_tibble_col( list(c = "three", d = list(4:5)), column_name = "data" ) </pre> <hr /><div style="text-align: center;">[Package <em>tibble</em> version 3.1.8 <a href="00Index.html">Index</a>]</div> </body></html>