R 패키지 메타데이터와 수집 신호를 모아 봅니다.
첫 화면에서 판단해야 할 수집 신호를 먼저 배치합니다.
DESCRIPTION에서 감지한 backend 관련 package입니다.
기본 메타데이터를 작은 카드와 토큰으로 압축합니다.
cpp11 (>= 0.4.0)| Package | Type | Spec |
|---|---|---|
| cli CRAN · 1.3.2 · 2026-05-30 | Imports | cli (>= 3.4.1) |
| dplyr CRAN · 1.3.2 · 2026-05-30 | Imports | dplyr (>= 1.1.0) |
| glue CRAN · 1.3.2 · 2026-05-30 | Imports | glue |
| lifecycle CRAN · 1.3.2 · 2026-05-30 | Imports | lifecycle (>= 1.0.3) |
| magrittr CRAN · 1.3.2 · 2026-05-30 | Imports | magrittr |
| purrr CRAN · 1.3.2 · 2026-05-30 | Imports | purrr (>= 1.0.1) |
| rlang CRAN · 1.3.2 · 2026-05-30 | Imports | rlang (>= 1.1.1) |
| stringr CRAN · 1.3.2 · 2026-05-30 | Imports | stringr (>= 1.5.0) |
| tibble CRAN · 1.3.2 · 2026-05-30 | Imports | tibble (>= 2.1.1) |
| tidyselect CRAN · 1.3.2 · 2026-05-30 | Imports | tidyselect (>= 1.2.1) |
| utils CRAN · 1.3.2 · 2026-05-30 | Imports | utils |
| vctrs CRAN · 1.3.2 · 2026-05-30 | Imports | vctrs (>= 0.5.2) |
| cpp11 CRAN · 1.3.2 · 2026-05-30 | LinkingTo | cpp11 (>= 0.4.0) |
| covr CRAN · 1.3.2 · 2026-05-30 | Suggests | covr |
| data.table CRAN · 1.3.2 · 2026-05-30 | Suggests | data.table |
| knitr CRAN · 1.3.2 · 2026-05-30 | Suggests | knitr |
| readr CRAN · 1.3.2 · 2026-05-30 | Suggests | readr |
| repurrrsive CRAN · 1.3.2 · 2026-05-30 | Suggests | repurrrsive (>= 1.1.0) |
| rmarkdown CRAN · 1.3.2 · 2026-05-30 | Suggests | rmarkdown |
| testthat CRAN · 1.3.2 · 2026-05-30 | Suggests | testthat (>= 3.0.0) |
| 검색 결과가 없습니다. | ||
| Package | Type | Spec |
|---|---|---|
| bSi 1.0.0 CRAN · 2026-05-30 | Depends | tidyr |
| bunching 0.8.6 CRAN · 2026-05-30 | Depends | tidyr (>= 0.8.2) |
| ClassificationEnsembles 1.0.2 CRAN · 2026-05-30 | Depends | tidyr |
| countmaskr 0.1.1 CRAN · 2026-05-30 | Depends | tidyr |
| diathor 0.1.5 CRAN · 2026-05-30 | Depends | tidyr |
| ForecastingEnsembles 0.5.1 CRAN · 2026-05-30 | Depends | tidyr |
| GauPro 0.2.17 CRAN · 2026-05-30 | Depends | tidyr |
| geotoolsR 1.2.1 CRAN · 2026-05-30 | Depends | tidyr |
| ggmcmc 1.5.1.2 CRAN · 2026-05-30 | Depends | tidyr (>= 1.1.0) |
| inti 0.6.92 CRAN · 2026-05-30 | Depends | tidyr |
| LogisticEnsembles 1.0.2 CRAN · 2026-05-30 | Depends | tidyr |
| NumericEnsembles 1.2 CRAN · 2026-05-30 | Depends | tidyr |
| photosynthesisLRC 1.0.6 CRAN · 2026-05-30 | Depends | tidyr (>= 1.3.1) |
| QurvE 1.1.2 CRAN · 2026-05-30 | Depends | tidyr |
| radiant.data 1.6.8 CRAN · 2026-05-30 | Depends | tidyr (>= 0.8.2) |
| RCPA 0.2.8 CRAN · 2026-05-30 | Depends | tidyr |
| Riex 1.0.2 CRAN · 2026-05-30 | Depends | tidyr |
| rollup 0.1.0 CRAN · 2026-05-30 | Depends | tidyr |
| saccadr 0.1.3 CRAN · 2026-05-30 | Depends | tidyr |
| sfc 0.1.1 CRAN · 2026-05-30 | Depends | tidyr |
| shinySIR 0.1.2 CRAN · 2026-05-14 | Depends | tidyr (>= 0.8.3) |
| textanalyzer 0.2.0 CRAN · 2026-05-30 | Depends | tidyr |
| ushr 0.2.3 CRAN · 2026-05-14 | Depends | tidyr (>= 0.8.3) |
| VectorCodeR 0.2.0 CRAN · 2026-05-30 | Depends | tidyr |
| abba 0.2.0 CRAN · 2026-05-30 | Imports | tidyr |
| ABCDscores 7.0.0 CRAN · 2026-05-30 | Imports | tidyr |
| abjutils 0.3.2 CRAN · 2026-05-30 | Imports | tidyr |
| abstr 0.4.2 CRAN · 2026-05-30 | Imports | tidyr (>= 1.1.3) |
| academictwitteR 0.3.1 CRAN · 2026-05-30 | Imports | tidyr |
| accelEE 0.3.1 CRAN · 2026-05-30 | Imports | tidyr |
| acledR 1.0.1 CRAN · 2026-05-30 | Imports | tidyr |
| activAnalyzer 2.1.2 CRAN · 2026-05-30 | Imports | tidyr |
| activPAL 0.1.4 CRAN · 2026-05-30 | Imports | tidyr |
| actogrammr 0.2.3 CRAN · 2026-05-30 | Imports | tidyr |
| actuary 0.1.2 CRAN · 2026-05-30 | Imports | tidyr |
| actxps 1.6.1 CRAN · 2026-05-30 | Imports | tidyr |
| adabag 5.1 CRAN · 2026-05-30 | Imports | tidyr |
| adas.utils 1.4.0 CRAN · 2026-05-30 | Imports | tidyr |
| adepro 4.2.7 CRAN · 2026-05-30 | Imports | tidyr |
| adheRenceRX 1.0.0 CRAN · 2026-05-30 | Imports | tidyr |
| admiral 1.4.2 CRAN · 2026-05-30 | Imports | tidyr (>= 1.0.2) |
| admiraldev 1.4.1 CRAN · 2026-05-30 | Imports | tidyr (>= 1.0.2) |
| admiralneuro 0.2.1 CRAN · 2026-05-30 | Imports | tidyr (>= 1.0.2) |
| admiralophtha 1.4.0 CRAN · 2026-05-30 | Imports | tidyr (>= 1.0.2) |
| admiralvaccine 0.6.0 CRAN · 2026-05-30 | Imports | tidyr (>= 1.0.2) |
| adobeanalyticsr 0.5.1 CRAN · 2026-05-30 | Imports | tidyr (>= 1.0.0) |
| adproclus 2.0.1 CRAN · 2026-05-30 | Imports | tidyr |
| adventr 0.1.8 CRAN · 2026-05-30 | Imports | tidyr |
| aeddo 0.1.1 CRAN · 2026-05-30 | Imports | tidyr |
| aedseo 1.1.0 CRAN · 2026-05-30 | Imports | tidyr |
| AEenrich 1.1.1 CRAN · 2026-05-30 | Imports | tidyr |
| aelab 1.1.3 CRAN · 2026-05-30 | Imports | tidyr |
| AeRobiology 2.0.2 CRAN · 2026-05-30 | Imports | tidyr |
| AeroSampleR 0.3.0 CRAN · 2026-05-30 | Imports | tidyr |
| afdx 1.1.2 CRAN · 2026-05-30 | Imports | tidyr |
| aftables 2.0.1 CRAN · 2026-05-30 | Imports | tidyr |
| AgeBandDecomposition 2.0.1 CRAN · 2026-05-30 | Imports | tidyr |
| AgePopDenom 1.2.3 CRAN · 2026-05-30 | Imports | tidyr |
| AgeTopicModels 0.3.0 CRAN · 2026-05-30 | Imports | tidyr |
| aggreCAT 1.1.0 CRAN · 2026-05-30 | Imports | tidyr |
| agregR 1.0.3 CRAN · 2026-05-30 | Imports | tidyr |
| agricolaeplotr 1.0.0 CRAN · 2026-05-30 | Imports | tidyr |
| AgriDiversiX 0.1.0 CRAN · 2026-05-30 | Imports | tidyr |
| agriutilities 1.2.3 CRAN · 2026-05-30 | Imports | tidyr |
| agrobox 0.3.0 CRAN · 2026-05-30 | Imports | tidyr |
| agua 0.1.4 CRAN · 2026-05-30 | Imports | tidyr |
| agvgd 0.1.2 CRAN · 2026-05-30 | Imports | tidyr |
| AHPGaussian 0.1.3 CRAN · 2026-05-30 | Imports | tidyr |
| AHPWR 0.1.2 CRAN · 2026-05-30 | Imports | tidyr |
| AIBias 0.1.1 CRAN · 2026-05-30 | Imports | tidyr (>= 1.3.0) |
| aihuman 1.0.1 CRAN · 2026-05-30 | Imports | tidyr |
| aire.zmvm 1.0.1 CRAN · 2026-05-30 | Imports | tidyr |
| airship 1.4.3 CRAN · 2026-05-30 | Imports | tidyr |
| airt 0.2.2 CRAN · 2026-05-30 | Imports | tidyr |
| AIscreenR 0.3.2 CRAN · 2026-05-30 | Imports | tidyr |
| alakazam 1.4.3 CRAN · 2026-05-30 | Imports | tidyr (>= 1.0) |
| ale 0.5.3 CRAN · 2026-05-30 | Imports | tidyr |
| alfred 0.2.1 CRAN · 2026-05-30 | Imports | tidyr |
| alien 1.0.2 CRAN · 2026-05-30 | Imports | tidyr |
| AlignLV 0.1.0.0 CRAN · 2026-05-30 | Imports | tidyr |
| allestimates 0.2.3 CRAN · 2026-05-30 | Imports | tidyr |
| allofus 1.2.0 CRAN · 2026-05-30 | Imports | tidyr |
| alookr 0.5.1 CRAN · 2026-05-30 | Imports | tidyr |
| alphavantagepf 0.3.2 CRAN · 2026-05-30 | Imports | tidyr (>= 0.6.3) |
| alphavantager 0.1.3 CRAN · 2026-05-30 | Imports | tidyr (>= 0.6.3) |
| amadeus 2.0.0 CRAN · 2026-05-30 | Imports | tidyr |
| ambiR 0.1.1 CRAN · 2026-05-30 | Imports | tidyr |
| amp 1.0.0 CRAN · 2026-05-30 | Imports | tidyr |
| amt 0.3.1.0 CRAN · 2026-05-30 | Imports | tidyr (>= 1.0.0) |
| anabel 3.0.2 CRAN · 2026-05-30 | Imports | tidyr (>= 1.2) |
| Analitica 2.2.0 CRAN · 2026-05-30 | Imports | tidyr |
| aNCA 0.1.0 CRAN · 2026-05-30 | Imports | tidyr |
| AnimalSequences 0.2.0 CRAN · 2026-05-30 | Imports | tidyr |
| animbook 1.0.1 CRAN · 2026-05-30 | Imports | tidyr |
| anipaths 0.10.6 CRAN · 2026-05-30 | Imports | tidyr |
| annotater 0.2.4 CRAN · 2026-05-30 | Imports | tidyr |
| anomalize 0.3.0 CRAN · 2026-05-30 | Imports | tidyr (>= 1.0.0) |
| anomaly 4.3.3 CRAN · 2026-05-30 | Imports | tidyr |
| anovapowersim 1.0.0 CRAN · 2026-05-30 | Imports | tidyr |
| AntibodyForests 1.1.0 CRAN · 2026-05-30 | Imports | tidyr |
| AntsNet 1.0.0 CRAN · 2026-05-30 | Imports | tidyr |
| anyflights 0.3.5 CRAN · 2026-05-30 | Imports | tidyr |
| aoristic 1.1.1 CRAN · 2026-05-30 | Imports | tidyr |
| apa7 0.1.3 CRAN · 2026-05-30 | Imports | tidyr |
| APCtools 1.0.8 CRAN · 2026-05-30 | Imports | tidyr |
| aplotExtra 0.0.4 CRAN · 2026-05-30 | Imports | tidyr |
| apmx 1.1.1 CRAN · 2026-05-30 | Imports | tidyr |
| applicable 0.2.1 CRAN · 2026-05-30 | Imports | tidyr |
| APRScenario 0.0.3.1 CRAN · 2026-05-30 | Imports | tidyr |
| AQEval 0.6.11 CRAN · 2026-05-30 | Imports | tidyr |
| AquaticLifeHistory 1.0.6 CRAN · 2026-05-30 | Imports | tidyr |
| archiveRetriever 0.4.1 CRAN · 2026-05-30 | Imports | tidyr |
| arcpullr 0.3.2 CRAN · 2026-05-30 | Imports | tidyr (>= 1.3.1) |
| ARDECO 2.2.3 CRAN · 2026-05-30 | Imports | tidyr |
| ARGOS 0.1.1 CRAN · 2026-05-30 | Imports | tidyr |
| arulesViz 1.5.4 CRAN · 2026-05-30 | Imports | tidyr |
| ARUtools 0.7.3 CRAN · 2026-05-30 | Imports | tidyr |
| ASML 1.1.0 CRAN · 2026-05-30 | Imports | tidyr |
| aspline 0.2.0 CRAN · 2026-05-30 | Imports | tidyr |
| astronomR 0.1.0 CRAN · 2026-05-30 | Imports | tidyr |
| 검색 결과가 없습니다. | ||
| Type | Packages |
|---|---|
| Depends | 24 |
| Imports | 2,361 |
| Suggests | 620 |
| Enhances | 1 |
NEWS code{white-space: pre-wrap;} span.smallcaps{font-variant: small-caps;} span.underline{text-decoration: underline;} div.column{display: inline-block; vertical-align: top; width: 50%;} div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;} ul.task-list{list-style: none;} pre > code.sourceCode { white-space: pre; position: relative; } pre > code.sourceCode > span { display: inline-block; line-height: 1.25; } pre > code.sourceCode > span:empty { height: 1.2em; } .sourceCode { overflow: visible; } code.sourceCode > span { color: inherit; text-decoration: inherit; } div.sourceCode { margin: 1em 0; } pre.sourceCode { margin: 0; } @media screen { div.sourceCode { overflow: auto; } } @media print { pre > code.sourceCode { white-space: pre-wrap; } pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; } } pre.numberSource code { counter-reset: source-line 0; } pre.numberSource code > span { position: relative; left: -4em; counter-increment: source-line; } pre.numberSource code > span > a:first-child::before { content: counter(source-line); position: relative; left: -1em; text-align: right; vertical-align: baseline; border: none; display: inline-block; -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; padding: 0 4px; width: 4em; color: #aaaaaa; } pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; } div.sourceCode { } @media screen { pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; } } code span.al { color: #ff0000; font-weight: bold; } /* Alert */ code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */ code span.at { color: #7d9029; } /* Attribute */ code span.bn { color: #40a070; } /* BaseN */ code span.bu { color: #008000; } /* BuiltIn */ code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */ code span.ch { color: #4070a0; } /* Char */ code span.cn { color: #880000; } /* Constant */ code span.co { color: #60a0b0; font-style: italic; } /* Comment */ code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */ code span.do { color: #ba2121; font-style: italic; } /* Documentation */ code span.dt { color: #902000; } /* DataType */ code span.dv { color: #40a070; } /* DecVal */ code span.er { color: #ff0000; font-weight: bold; } /* Error */ code span.ex { } /* Extension */ code span.fl { color: #40a070; } /* Float */ code span.fu { color: #06287e; } /* Function */ code span.im { color: #008000; font-weight: bold; } /* Import */ code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */ code span.kw { color: #007020; font-weight: bold; } /* Keyword */ code span.op { color: #666666; } /* Operator */ code span.ot { color: #007020; } /* Other */ code span.pp { color: #bc7a00; } /* Preprocessor */ code span.sc { color: #4070a0; } /* SpecialChar */ code span.ss { color: #bb6688; } /* SpecialString */ code span.st { color: #4070a0; } /* String */ code span.va { color: #19177c; } /* Variable */ code span.vs { color: #4070a0; } /* VerbatimString */ code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */ tidyr 1.3.2 fill() gains a .by argument as an alternative to dplyr::group_by() for applying the fill per group, similar to nest(.by =) and dplyr::mutate(.by =) ( @olivroy , #1439). expand_grid() gains a new .vary argument, allowing users to control whether the first column varies fastest or slowest (#1543, @JamesHWade ). unnest_longer() now places indices_to columns before value columns (#1486, @andrewshibata ). unchop() produces a more helpful error message when columns cannot be cast to ptype ( @mgirlich , #1477). unite() no longer errors if you provide a selection that doesn’t select any columns. Instead, it returns a column containing the empty string (#1548, @catalamarti ). pivot_wider_spec() now throws a more informative error on non-data frame inputs ( @catalamarti , #1510). Fixed an internal error in pivot_wider() (#1609, @krlmlr ). R >=4.1.0 is now required, in line with the tidyverse standard of supporting the previous 5 minor releases of R (#1613). The base pipe is now used throughout the documentation (#1613). tidyr now requires dplyr >=1.1.0 (#1568, @catalamarti ). tidyr is now compliant with R’s C API (#1618). tidyr 1.3.1 pivot_wider now uses .by and |> syntax for the dplyr helper message to identify duplicates ( @boshek , #1516) tidyr 1.3.0 New features New family of consistent string separating functions: separate_wider_delim() , separate_wider_position() , separate_wider_regex() , separate_longer_delim() , and separate_longer_position() . These functions are thorough refreshes of separate() and extract() , featuring improved performance, greater consistency, a polished API, and a new approach for handling problems. They use stringr and supersede extract() , separate() , and separate_rows() (#1304). The named character vector interface used in separate_wider_regex() is very similar to the nc package by Toby Dylan Hocking. nest() gains a .by argument which allows you to specify the columns to nest by (rather than the columns to nest, i.e. through ... ). Additionally, the .key argument is no longer deprecated, and is used whenever ... isn’t specified (#1458). unnest_longer() gains a keep_empty argument like unnest() (#1339). pivot_longer() gains a cols_vary argument for controlling the ordering of the output rows relative to their original row number (#1312). New datasets who2 , household , cms_patient_experience , and cms_patient_care to demonstrate various tidying challenges (#1333). Breaking changes The ... argument of both pivot_longer() and pivot_wider() has been moved to the front of the function signature, after the required arguments but before the optional ones. Additionally, pivot_longer_spec() , pivot_wider_spec() , build_longer_spec() , and build_wider_spec() have all gained ... arguments in a similar location. This change allows us to more easily add new features to the pivoting functions without breaking existing CRAN packages and user scripts. pivot_wider() provides temporary backwards compatible support for the case of a single unnamed argument that previously was being positionally matched to id_cols . This one special case still works, but will throw a warning encouraging you to explicitly name the id_cols argument. To read more about this pattern, see https://design.tidyverse.org/dots-after-required.html (#1350). Lifecycle changes All functions deprecated in tidyr 1.0 and 1.2 (the old lazyeval functions ending in _ and various arguments to unnest() ) now warn on every use. They will be made defunct in 2024 (#1406). Rectangling unnest_longer() now consistently drops rows with either NULL or empty vectors (like integer() ) by default. Set the new keep_empty argument to TRUE to retain them. Previously, keep_empty = TRUE was implicitly being used for NULL , while keep_empty = FALSE was being used for empty vectors, which was inconsistent with all other tidyr verbs with this argument (#1363). unnest_longer() now uses "" in the index column for fully unnamed vectors. It also now consistently uses NA in the index column for empty vectors that are “kept” by keep_empty = TRUE (#1442). unnest_wider() now errors if any values being unnested are unnamed and names_sep is not provided (#1367). unnest_wider() now generates automatic names for partially unnamed vectors. Previously it only generated them for fully unnamed vectors, resulting in a strange mix of automatic names and name-repaired names (#1367). Bug fixes and minor improvements General Most tidyr functions now consistently disallow renaming during tidy-selection. Renaming was never meaningful in these functions, and previously either had no effect or caused problems (#1449, #1104). tidyr errors (including input validation) have been thoroughly reviewed and shoREADME code{white-space: pre-wrap;} span.smallcaps{font-variant: small-caps;} span.underline{text-decoration: underline;} div.column{display: inline-block; vertical-align: top; width: 50%;} div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;} ul.task-list{list-style: none;} pre > code.sourceCode { white-space: pre; position: relative; } pre > code.sourceCode > span { display: inline-block; line-height: 1.25; } pre > code.sourceCode > span:empty { height: 1.2em; } .sourceCode { overflow: visible; } code.sourceCode > span { color: inherit; text-decoration: inherit; } div.sourceCode { margin: 1em 0; } pre.sourceCode { margin: 0; } @media screen { div.sourceCode { overflow: auto; } } @media print { pre > code.sourceCode { white-space: pre-wrap; } pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; } } pre.numberSource code { counter-reset: source-line 0; } pre.numberSource code > span { position: relative; left: -4em; counter-increment: source-line; } pre.numberSource code > span > a:first-child::before { content: counter(source-line); position: relative; left: -1em; text-align: right; vertical-align: baseline; border: none; display: inline-block; -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; padding: 0 4px; width: 4em; color: #aaaaaa; } pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; } div.sourceCode { } @media screen { pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; } } code span.al { color: #ff0000; font-weight: bold; } /* Alert */ code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */ code span.at { color: #7d9029; } /* Attribute */ code span.bn { color: #40a070; } /* BaseN */ code span.bu { color: #008000; } /* BuiltIn */ code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */ code span.ch { color: #4070a0; } /* Char */ code span.cn { color: #880000; } /* Constant */ code span.co { color: #60a0b0; font-style: italic; } /* Comment */ code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */ code span.do { color: #ba2121; font-style: italic; } /* Documentation */ code span.dt { color: #902000; } /* DataType */ code span.dv { color: #40a070; } /* DecVal */ code span.er { color: #ff0000; font-weight: bold; } /* Error */ code span.ex { } /* Extension */ code span.fl { color: #40a070; } /* Float */ code span.fu { color: #06287e; } /* Function */ code span.im { color: #008000; font-weight: bold; } /* Import */ code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */ code span.kw { color: #007020; font-weight: bold; } /* Keyword */ code span.op { color: #666666; } /* Operator */ code span.ot { color: #007020; } /* Other */ code span.pp { color: #bc7a00; } /* Preprocessor */ code span.sc { color: #4070a0; } /* SpecialChar */ code span.ss { color: #bb6688; } /* SpecialString */ code span.st { color: #4070a0; } /* String */ code span.va { color: #19177c; } /* Variable */ code span.vs { color: #4070a0; } /* VerbatimString */ code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */ tidyr Overview The goal of tidyr is to help you create tidy data . Tidy data is data where: Each variable is a column; each column is a variable. Each observation is a row; each row is an observation. Each value is a cell; each cell is a single value. Tidy data describes a standard way of storing data that is used wherever possible throughout the tidyverse . If you ensure that your data is tidy, you’ll spend less time fighting with the tools and more time working on your analysis. Learn more about tidy data in vignette("tidy-data") . Installation # The easiest way to get tidyr is to install the whole tidyverse: install.packages ( "tidyverse" ) # Alternatively, install just tidyr: install.packages ( "tidyr" ) # Or the development version from GitHub: # install.packages("pak") pak :: pak ( "tidyverse/tidyr" ) Cheatsheet Getting started library (tidyr) tidyr functions fall into five main categories: “Pivoting” which converts between long and wide forms. tidyr 1.0.0 introduces pivot_longer() and pivot_wider() , replacing the older spread() and gather() functions. See vignette("pivot") for more details. “Rectangling”, which turns deeply nested lists (as from JSON) into tidy tibbles. See unnest_longer() , unnest_wider() , hoist() , and vignette("rectangle") for more details. Nesting converts grouped data to a form where each group becomes a single row containing a nested data frame, and unnesting does the opposite. See nest() , unnest() , and vignette("nest") for more details. Splitting and combining character columns. Use separate_wider_delim() , separate_wider_position() , and separate_wider_regex() to pull a single character column into multiple columns; use unite() to combine multiple columns into a single character column. Make implicit missing values explicit with complete() ; make explicit missing values implicit with drop_na() ; replace missing values with next/previous value with fill() , or a known value with replace_na() . Related work tidyr supersedes reshape2 (2010-2014) and reshape (2005-2010). Somewhat counterintuitively, each iteration of the package has done less. tidyr is designed specifically for tidying data, not general reshaping (reshape2), or the general aggregation (reshape). data.table provides high-performance implementations of melt() and dcast() If you’d like to read more about data reshaping from a CS perspective, I’d recommend the following three papers: Wrangler: Interactive visual specification of data transformation scripts An interactive framework for data cleaning (Potter’s wheel) On efficiently implementing SchemaSQL on a SQL database system To guide your reading, here’s a translation between the terminology used in different places: tidyr 1.0.0 pivot longer pivot wider tidyr < 1.0.0 gather spread reshape(2) melt cast spreadsheets unpivot pivot databases fold unfold Getting help If you encounter a clear bug, please file a minimal reproducible example on github . For questions and other discussion, please use forum.posit.co . Please note that the tidyr project is released with a Contributor Code of Conduct . By contributing to this project, you agree to abide by its terms.Help for package tidyr const macros = { "\\R": "\\textsf{R}", "\\mbox": "\\text", "\\code": "\\texttt"}; function processMathHTML() { var l = document.getElementsByClassName('reqn'); for (let e of l) { katex.render(e.textContent, e, { throwOnError: false, macros }); } return; } Package {tidyr} Contents tidyr-package %>% billboard check_pivot_spec chop cms_patient_experience complete construction deprecated-se drop_na expand expand_grid extract extract_numeric fill fish_encounters full_seq gather hoist household nest nest_legacy pack pivot_longer pivot_longer_spec pivot_wider pivot_wider_spec reexports relig_income replace_na separate separate_longer_delim separate_rows separate_wider_delim smiths spread table1 tidyr_data_masking tidyr_legacy tidyr_tidy_select uncount unite unnest unnest_auto unnest_longer unnest_wider us_rent_income who world_bank_pop Title: Tidy Messy Data Version: 1.3.2 Description: Tools to help to create tidy data, where each column is a variable, each row is an observation, and each cell contains a single value. 'tidyr' contains tools for changing the shape (pivoting) and hierarchy (nesting and 'unnesting') of a dataset, turning deeply nested lists into rectangular data frames ('rectangling'), and extracting values out of string columns. It also includes tools for working with missing values (both implicit and explicit). License: MIT + file LICENSE URL: https://tidyr.tidyverse.org , https://github.com/tidyverse/tidyr BugReports: https://github.com/tidyverse/tidyr/issues Depends: R (≥ 4.1.0) Imports: cli (≥ 3.4.1), dplyr (≥ 1.1.0), glue, lifecycle (≥ 1.0.3), magrittr, purrr (≥ 1.0.1), rlang (≥ 1.1.1), stringr (≥ 1.5.0), tibble (≥ 2.1.1), tidyselect (≥ 1.2.1), utils, vctrs (≥ 0.5.2) Suggests: covr, data.table, knitr, readr, repurrrsive (≥ 1.1.0), rmarkdown, testthat (≥ 3.0.0) LinkingTo: cpp11 (≥ 0.4.0) VignetteBuilder: knitr Config/build/compilation-database: true Config/Needs/website: tidyverse/tidytemplate Config/testthat/edition: 3 Encoding: UTF-8 LazyData: true RoxygenNote: 7.3.3 NeedsCompilation: yes Packaged: 2025-12-17 23:35:11 UTC; hadleywickham Author: Hadley Wickham [aut, cre], Davis Vaughan [aut], Maximilian Girlich [aut], Kevin Ushey [ctb], Posit Software, PBC [cph, fnd] Maintainer: Hadley Wickham <hadley@posit.co> Repository: CRAN Date/Publication: 2025-12-19 09:20:02 UTC tidyr: Tidy Messy Data Description Tools to help to create tidy data, where each column is a variable, each row is an observation, and each cell contains a single value. 'tidyr' contains tools for changing the shape (pivoting) and hierarchy (nesting and 'unnesting') of a dataset, turning deeply nested lists into rectangular data frames ('rectangling'), and extracting values out of string columns. It also includes tools for working with missing values (both implicit and explicit). Author(s) Maintainer : Hadley Wickham hadley@posit.co Authors: Davis Vaughan davis@posit.co Maximilian Girlich Other contributors: Kevin Ushey kevin@posit.co [contributor] Posit Software, PBC [copyright holder, funder] See Also Useful links: https://tidyr.tidyverse.org https://github.com/tidyverse/tidyr Report bugs at https://github.com/tidyverse/tidyr/issues Pipe operator Description See %>% for more details. Usage lhs %>% rhs Song rankings for Billboard top 100 in the year 2000 Description Song rankings for Billboard top 100 in the year 2000 Usage billboard Format A dataset with variables: artist Artist name track Song name date.enter Date the song entered the top 100 wk1 – wk76 Rank of the song in each week after it entered Source The "Whitburn" project, https://waxy.org/2008/05/the_whitburn_project/ , (downloaded April 2008) Check assumptions about a pivot spec Description check_pivot_spec() is a developer facing helper function for validating the pivot spec used in pivot_longer_spec() or pivot_wider_spec() . It is only useful if you are extending pivot_longer() or pivot_wider() with new S3 methods. check_pivot_spec() makes the following assertions: spec must be a data frame. spec must have a character column named .name . spec must have a character column named .value . The .name column must be unique. The .name and .value columns must be the first two columns in the data frame, and will be reordered if that is not true. Usage check_pivot_spec(spec, call = caller_env()) Arguments spec A specification data frame. This is useful for more complex pivots because it gives you greater control on how metadata stored in the columns become column names in the result. Must be a data frame containing character .name and .value columns. Additional columns in spec should be named to match columns in the long format of the dataset and contain values corresponding to columns pivoted from the wide format. The special .seq variable is used to disambiguate rows internally; it is automatically removed after pivoting. Examples # A valid spec spec <- tibble(.name = "a", .value = "b", foo = 1) check_pivot_spec(spec) spec <- tibble(.name = "a") try(check_pivot_spec(spec)) # `.name` and `.value` are forced to be the first two columns spec <- tibble(foo = 1, .value = "b", .name = "a") check_pivot_spec(spec) Chop and unchop Description Chopping and unchopping preserve the width of a data frame, changing its length. chop() makes df shorter by converting rows within each group into list-columns. unchop() makes df longer by expanding list-columns so that each element of the list-column gets its own row in the output. chop() and unchop() are building blocks for more complicated functions (like unnest() , unnest_longer() , and unnest_wider() ) and are generally more suitable for programming than interactive data analysis. Usage chop(data, cols, ..., error_call = current_env()) unchop( data, cols, ..., keep_empty = FALSE, ptype = NULL, error_call = current_env() ) Arguments data A data frame. cols < tidy-select > Columns to chop or unchop. For unchop() , each column should be a list-column containing generalised vectors (e.g. any mix of NULL s, atomic vector, S3 vectors, a lists, or data frames). ... These dots are for future extensions and must be empty. error_call The execution environment of a currently running function, e.g. caller_env() . The function will be mentioned in error messages as the source of the error. See the call argument of abort() for more information. keep_empty By default, you get one row of output for each element of the list that you are unchopping/unnesting. This means that if there's a size-0 element (like NULL or an empty data frame or vector), then that entire row will be dropped from the output. If you want to preserve all rows, use keep_empty = TRUE to replace size-0 elements with a single row of missing values. ptype Optionally, a named list of column name-prototype pairs to coerce cols to, overriding the default that will be guessed from combining the individual values. Alternatively, a single empty ptype can be supplied, which will be applied to all cols . Details Generally, unchopping is more useful than chopping because it simplifies a complex data structure, and nest() ing is usually more appropriate than chop() ing since it better preserves the connections between observations. chop() creates list-columns of class vctrs::list_of() to ensure consistent behaviour when the chopped data frame is emptied. For instance this helps getting back the original column types after the roundtrip chop and unchop. Because <list_of> keeps tracks of the type of its elements, unchop() is able to reconstitute the correct vector type even for empty list-columns. Examples # Chop ---------------------------------------------------------------------- df <- tibble(x = c(1, 1, 1, 2, 2, 3), y = 1:6, z = 6:1) # Note that we get one row of output for each unique combination of # non-chopped variables df |> chop(c(y, z)) # cf nest df |> nest(data = c(y, z)) # Unchop -------------------------------------------------------------------- df <- tibble(x = 1:4, ySee [magrittr]%>% for more details.
lhs %>% rhsSong rankings for Billboard top 100 in the year 2000
billboardThe "Whitburn" project, https://waxy.org/2008/05/the_whitburn_project/, (downloaded April 2008)check_pivot_spec() is a developer facing helper function for validating the pivot spec used in [=pivot_longer_spec]pivot_longer_spec() or [=pivot_wider_spec]pivot_wider_spec(). It is only useful if you are extending [=pivot_longer]pivot_longer() or [=pivot_wider]pivot_wider() with new S3 methods. check_pivot_spec() makes the following assertions: spec must be a data frame. spec must have a character column named .name. spec must have a character column named .value. The .name column must be unique. The .name and .value columns must be the first two columns in the data frame, and will be reordered if that is not true.
check_pivot_spec(spec, call = caller_env())# A valid spec spec <- tibble(.name = "a", .value = "b", foo = 1) check_pivot_spec(spec) spec <- tibble(.name = "a") try(check_pivot_spec(spec)) # `.name` and `.value` are forced to be the first two columns spec <- tibble(foo = 1, .value = "b", .name = "a") check_pivot_spec(spec)Chopping and unchopping preserve the width of a data frame, changing its length. chop() makes df shorter by converting rows within each group into list-columns. unchop() makes df longer by expanding list-columns so that each element of the list-column gets its own row in the output. chop() and unchop() are building blocks for more complicated functions (like [=unnest]unnest(), [=unnest_longer]unnest_longer(), and [=unnest_wider]unnest_wider()) and are generally more suitable for programming than interactive data analysis.
chop(data, cols, ..., error_call = current_env()) unchop( data, cols, ..., keep_empty = FALSE, ptype = NULL, error_call = current_env() )# Chop ---------------------------------------------------------------------- df <- tibble(x = c(1, 1, 1, 2, 2, 3), y = 1:6, z = 6:1) # Note that we get one row of output for each unique combination of # non-chopped variables df |> chop(c(y, z)) # cf nest df |> nest(data = c(y, z)) # Unchop -------------------------------------------------------------------- df <- tibble(x = 1:4, y = list(integer(), 1L, 1:2, 1:3)) df |> unchop(y) df |> unchop(y, keep_empty = TRUE) # unchop will error if the types are not compatible: df <- tibble(x = 1:2, y = list("1", 1:3)) try(df |> unchop(y)) # Unchopping a list-col of data frames must generate a df-col because # unchop leaves the column names unchanged df <- tibble(x = 1:3, y = list(NULL, tibble(x = 1), tibble(y = 1:2))) df |> unchop(y) df |> unchop(y, keep_empty = TRUE)Two datasets from public data provided the Centers for Medicare & Medicaid Services, https://data.cms.gov. cms_patient_experience contains some lightly cleaned data from "Hospice - Provider Data", which provides a list of hospice agencies along with some data on quality of patient care, https://data.cms.gov/provider-data/dataset/252m-zfp9. cms_patient_care "Doctors and Clinicians Quality Payment Program PY 2020 Virtual Group Public Reporting", https://data.cms.gov/provider-data/dataset/8c70-d353
cms_patient_experience cms_patient_carecms_patient_experience |> dplyr::distinct(measure_cd, measure_title) cms_patient_experience |> pivot_wider( id_cols = starts_with("org"), names_from = measure_cd, values_from = prf_rate ) cms_patient_care |> pivot_wider( names_from = type, values_from = score ) cms_patient_care |> pivot_wider( names_from = measure_abbr, values_from = score ) cms_patient_care |> pivot_wider( names_from = c(measure_abbr, type), values_from = score )Turns implicit missing values into explicit missing values. This is a wrapper around [=expand]expand(), [dplyr:mutate-joins]dplyr::full_join() and [=replace_na]replace_na() that's useful for completing missing combinations of data.
complete(data, ..., fill = list(), explicit = TRUE)df <- tibble( group = c(1:2, 1, 2), item_id = c(1:2, 2, 3), item_name = c("a", "a", "b", "b"), value1 = c(1, NA, 3, 4), value2 = 4:7 ) df # Combinations -------------------------------------------------------------- # Generate all possible combinations of `group`, `item_id`, and `item_name` # (whether or not they appear in the data) df |> complete(group, item_id, item_name) # Cross all possible `group` values with the unique pairs of # `(item_id, item_name)` that already exist in the data df |> complete(group, nesting(item_id, item_name)) # Within each `group`, generate all possible combinations of # `item_id` and `item_name` that occur in that group df |> dplyr::group_by(group) |> complete(item_id, item_name) # Supplying values for new rows --------------------------------------------- # Use `fill` to replace NAs with some value. By default, affects both new # (implicit) and pre-existing (explicit) missing values. df |> complete( group, nesting(item_id, item_name), fill = list(value1 = 0, value2 = 99) ) # Limit the fill to only the newly created (i.e. previously implicit) # missing values with `explicit = FALSE` df |> complete( group, nesting(item_id, item_name), fill = list(value1 = 0, value2 = 99), explicit = FALSE )Completed construction in the US in 2018
constructionCompletions of "New Residential Construction" found in Table 5 at https://www.census.gov/construction/nrc/xls/newresconst.xls (downloaded March 2019)htmlhttps://lifecycle.r-lib.org/articles/stages.html#deprecatedlifecycle-deprecated.svgoptions: alt='[Deprecated]'[Deprecated] tidyr used to offer twin versions of each verb suffixed with an underscore. These versions had standard evaluation (SE) semantics: rather than taking arguments by code, like NSE verbs, they took arguments by value. Their purpose was to make it possible to program with tidyr. However, tidyr now uses tidy evaluation semantics. NSE verbs still capture their arguments, but you can now unquote parts of these arguments. This offers full programmability with NSE verbs. Thus, the underscored versions are now superfluous. Unquoting triggers immediate evaluation of its operand and inlines the result within the captured expression. This result can be a value or an expression to be evaluated later with the rest of the argument. See vignette("programming", "dplyr") for more information.
complete_(data, cols, fill = list(), ...) drop_na_(data, vars) expand_(data, dots, ...) crossing_(x) nesting_(x) extract_( data, col, into, regex = "([[:alnum:]]+)", remove = TRUE, convert = FALSE, ... ) fill_(data, fill_cols, .direction = c("down", "up")) gather_( data, key_col, value_col, gather_cols, na.rm = FALSE, convert = FALSE, factor_key = FALSE ) nest_(...) separate_rows_(data, cols, sep = "[^[:alnum:].]+", convert = FALSE) separate_( data, col, into, sep = "[^[:alnum:]]+", remove = TRUE, convert = FALSE, extra = "warn", fill = "warn", ... ) spread_( data, key_col, value_col, fill = NA, convert = FALSE, drop = TRUE, sep = NULL ) unite_(data, col, from, sep = "_", remove = TRUE) unnest_(...)drop_na() drops rows where any column specified by ... contains a missing value.
drop_na(data, ...)df <- tibble(x = c(1, 2, NA), y = c("a", NA, "b")) df |> drop_na() df |> drop_na(x) vars <- "y" df |> drop_na(x, any_of(vars))expand() generates all combination of variables found in a dataset. It is paired with nesting() and crossing() helpers. crossing() is a wrapper around [=expand_grid]expand_grid() that de-duplicates and sorts its inputs; nesting() is a helper that only finds combinations already present in the data. expand() is often useful in conjunction with joins: use it with right_join() to convert implicit missing values to explicit missing values (e.g., fill in gaps in your data frame). use it with anti_join() to figure out which combinations are missing (e.g., identify gaps in your data frame).
expand(data, ..., .name_repair = "check_unique") crossing(..., .name_repair = "check_unique") nesting(..., .name_repair = "check_unique")# Finding combinations ------------------------------------------------------ fruits <- tibble( type = c("apple", "orange", "apple", "orange", "orange", "orange"), year = c(2010, 2010, 2012, 2010, 2011, 2012), size = factor( c("XS", "S", "M", "S", "S", "M"), levels = c("XS", "S", "M", "L") ), weights = rnorm(6, as.numeric(size) + 2) ) # All combinations, including factor levels that are not used fruits |> expand(type) fruits |> expand(size) fruits |> expand(type, size) fruits |> expand(type, size, year) # Only combinations that already appear in the data fruits |> expand(nesting(type)) fruits |> expand(nesting(size)) fruits |> expand(nesting(type, size)) fruits |> expand(nesting(type, size, year)) # Other uses ---------------------------------------------------------------- # Use with `full_seq()` to fill in values of continuous variables fruits |> expand(type, size, full_seq(year, 1)) fruits |> expand(type, size, 2010:2013) # Use `anti_join()` to determine which observations are missing all <- fruits |> expand(type, size, year) all all |> dplyr::anti_join(fruits) # Use with `right_join()` to fill in missing rows (like `complete()`) fruits |> dplyr::right_join(all) # Use with `group_by()` to expand within each group fruits |> dplyr::group_by(type) |> expand(year, size)expand_grid() is heavily motivated by [=expand.grid]expand.grid(). Compared to expand.grid(), it: Produces sorted output by varying the first column the slowest by default. Returns a tibble, not a data frame. Never converts strings to factors. Does not add any additional attributes. Can expand any generalised vector, including data frames.
expand_grid(..., .name_repair = "check_unique", .vary = "slowest")# Default behavior varies the first column "slowest" expand_grid(x = 1:3, y = 1:2) # Vary the first column "fastest", like `expand.grid()` expand_grid(x = 1:3, y = 1:2, .vary = "fastest") # Can also expand data frames expand_grid(df = tibble(x = 1:2, y = c(2, 1)), z = 1:3) # And matrices expand_grid(x1 = matrix(1:4, nrow = 2), x2 = matrix(5:8, nrow = 2))htmlhttps://lifecycle.r-lib.org/articles/stages.html#supersededlifecycle-superseded.svgoptions: alt='[Superseded]'[Superseded] extract() has been superseded in favour of [=separate_wider_regex]separate_wider_regex() because it has a more polished API and better handling of problems. Superseded functions will not go away, but will only receive critical bug fixes. Given a regular expression with capturing groups, extract() turns each group into a new column. If the groups don't match, or the input is NA, the output will be NA.
extract( data, col, into, regex = "([[:alnum:]]+)", remove = TRUE, convert = FALSE, ... )df <- tibble(x = c(NA, "a-b", "a-d", "b-c", "d-e")) df |> extract(x, "A") df |> extract(x, c("A", "B"), "([[:alnum:]]+)-([[:alnum:]]+)") # Now recommended df |> separate_wider_regex( x, patterns = c(A = "[[:alnum:]]+", "-", B = "[[:alnum:]]+") ) # If no match, NA: df |> extract(x, c("A", "B"), "([a-d]+)-([a-d]+)")DEPRECATED: please use readr::parse_number() instead.
extract_numeric(x)Fills missing values in selected columns using the next or previous entry. This is useful in the common output format where values are not repeated, and are only recorded when they change.
fill(data, ..., .by = NULL, .direction = c("down", "up", "downup", "updown"))# direction = "down" -------------------------------------------------------- # Value (year) is recorded only when it changes sales <- tibble::tribble( ~quarter, ~year, ~sales, "Q1", 2000, 66013, "Q2", NA, 69182, "Q3", NA, 53175, "Q4", NA, 21001, "Q1", 2001, 46036, "Q2", NA, 58842, "Q3", NA, 44568, "Q4", NA, 50197, "Q1", 2002, 39113, "Q2", NA, 41668, "Q3", NA, 30144, "Q4", NA, 52897, "Q1", 2004, 32129, "Q2", NA, 67686, "Q3", NA, 31768, "Q4", NA, 49094 ) # `fill()` defaults to replacing missing data from top to bottom sales |> fill(year) # direction = "up" ---------------------------------------------------------- # Value (pet_type) is missing above tidy_pets <- tibble::tribble( ~rank, ~pet_type, ~breed, 1L, NA, "Boston Terrier", 2L, NA, "Retrievers (Labrador)", 3L, NA, "Retrievers (Golden)", 4L, NA, "French Bulldogs", 5L, NA, "Bulldogs", 6L, "Dog", "Beagles", 1L, NA, "Persian", 2L, NA, "Maine Coon", 3L, NA, "Ragdoll", 4L, NA, "Exotic", 5L, NA, "Siamese", 6L, "Cat", "American Short" ) # For values that are missing above you can use `.direction = "up"` tidy_pets |> fill(pet_type, .direction = "up") # direction = "downup" ------------------------------------------------------ # Value (n_squirrels) is missing above and below within a group squirrels <- tibble::tribble( ~group, ~name, ~role, ~n_squirrels, 1, "Sam", "Observer", NA, 1, "Mara", "Scorekeeper", 8, 1, "Jesse", "Observer", NA, 1, "Tom", "Observer", NA, 2, "Mike", "Observer", NA, 2, "Rachael", "Observer", NA, 2, "Sydekea", "Scorekeeper", 14, 2, "Gabriela", "Observer", NA, 3, "Derrick", "Observer", NA, 3, "Kara", "Scorekeeper", 9, 3, "Emily", "Observer", NA, 3, "Danielle", "Observer", NA ) # The values are inconsistently missing by position within the `group`. # Use `.direction = "downup"` to fill missing values in both directions # and `.by = group` to apply the fill per group. squirrels |> fill(n_squirrels, .direction = "downup", .by = group) # If you want, you can also supply a data frame grouped with `group_by()`, # but don't forget to `ungroup()`! squirrels |> dplyr::group_by(group) |> fill(n_squirrels, .direction = "downup") |> dplyr::ungroup()Information about fish swimming down a river: each station represents an autonomous monitor that records if a tagged fish was seen at that location. Fish travel in one direction (migrating downstream). Information about misses is just as important as hits, but is not directly recorded in this form of the data.
fish_encountersDataset provided by Myfanwy Johnston; more details at https://fishsciences.github.io/post/visualizing-fish-encounter-histories/This is useful if you want to fill in missing values that should have been observed but weren't. For example, full_seq(c(1, 2, 4, 6), 1) will return 1:6.
full_seq(x, period, tol = 1e-06)full_seq(c(1, 2, 4, 5, 10), 1)htmlhttps://lifecycle.r-lib.org/articles/stages.html#supersededlifecycle-superseded.svgoptions: alt='[Superseded]'[Superseded] Development on gather() is complete, and for new code we recommend switching to pivot_longer(), which is easier to use, more featureful, and still under active development. df |> gather("key", "value", x, y, z) is equivalent to df |> pivot_longer(c(x, y, z), names_to = "key", values_to = "value") See more details in vignette("pivot").
gather( data, key = "key", value = "value", ..., na.rm = FALSE, convert = FALSE, factor_key = FALSE )# From https://stackoverflow.com/questions/1181060 stocks <- tibble( time = as.Date("2009-01-01") + 0:9, X = rnorm(10, 0, 1), Y = rnorm(10, 0, 2), Z = rnorm(10, 0, 4) ) gather(stocks, "stock", "price", -time) stocks |> gather("stock", "price", -time) # get first observation for each Species in iris data -- base R mini_iris <- iris[c(1, 51, 101), ] # gather Sepal.Length, Sepal.Width, Petal.Length, Petal.Width gather(mini_iris, key = "flower_att", value = "measurement", Sepal.Length, Sepal.Width, Petal.Length, Petal.Width) # same result but less verbose gather(mini_iris, key = "flower_att", value = "measurement", -Species)hoist() allows you to selectively pull components of a list-column into their own top-level columns, using the same syntax as [purrr:pluck]purrr::pluck(). Learn more in vignette("rectangle").
hoist( .data, .col, ..., .remove = TRUE, .simplify = TRUE, .ptype = NULL, .transform = NULL )df <- tibble( character = c("Toothless", "Dory"), metadata = list( list( species = "dragon", color = "black", films = c( "How to Train Your Dragon", "How to Train Your Dragon 2", "How to Train Your Dragon: The Hidden World" ) ), list( species = "blue tang", color = "blue", films = c("Finding Nemo", "Finding Dory") ) ) ) df # Extract only specified components df |> hoist(metadata, "species", first_film = list("films", 1L), third_film = list("films", 3L) )This dataset is based on an example in vignette("datatable-reshape", package = "data.table")
householdNesting creates a list-column of data frames; unnesting flattens it back out into regular columns. Nesting is implicitly a summarising operation: you get one row for each group defined by the non-nested columns. This is useful in conjunction with other summaries that work with whole datasets, most notably models. Learn more in vignette("nest").
nest(.data, ..., .by = NULL, .key = NULL, .names_sep = NULL)df <- tibble(x = c(1, 1, 1, 2, 2, 3), y = 1:6, z = 6:1) # Specify variables to nest using name-variable pairs. # Note that we get one row of output for each unique combination of # non-nested variables. df |> nest(data = c(y, z)) # Specify variables to nest by (rather than variables to nest) using `.by` df |> nest(.by = x) # In this case, since `...` isn't used you can specify the resulting column # name with `.key` df |> nest(.by = x, .key = "cols") # Use tidyselect syntax and helpers, just like in `dplyr::select()` df |> nest(data = any_of(c("y", "z"))) # `...` and `.by` can be used together to drop columns you no longer need, # or to include the columns you are nesting by in the inner data frame too. # This drops `z`: df |> nest(data = y, .by = x) # This includes `x` in the inner data frame: df |> nest(data = everything(), .by = x) # Multiple nesting structures can be specified at once iris |> nest(petal = starts_with("Petal"), sepal = starts_with("Sepal")) iris |> nest(width = contains("Width"), length = contains("Length")) # Nesting a grouped data frame nests all variables apart from the group vars fish_encounters |> dplyr::group_by(fish) |> nest() # That is similar to `nest(.by = )`, except here the result isn't grouped fish_encounters |> nest(.by = fish) # Nesting is often useful for creating per group models mtcars |> nest(.by = cyl) |> dplyr::mutate(models = lapply(data, function(df) lm(mpg ~ wt, data = df)))htmlhttps://lifecycle.r-lib.org/articles/stages.html#supersededlifecycle-superseded.svgoptions: alt='[Superseded]'[Superseded] tidyr 1.0.0 introduced a new syntax for [=nest]nest() and [=unnest]unnest(). The majority of existing usage should be automatically translated to the new syntax with a warning. However, if you need to quickly roll back to the previous behaviour, these functions provide the previous interface. To make old code work as is, add the following code to the top of your script: html<div class="sourceCode">library(tidyr) nest <- nest_legacy unnest <- unnest_legacy html</div>
nest_legacy(data, ..., .key = "data") unnest_legacy(data, ..., .drop = NA, .id = NULL, .sep = NULL, .preserve = NULL)# Nest and unnest are inverses df <- tibble(x = c(1, 1, 2), y = 3:1) df |> nest_legacy(y) df |> nest_legacy(y) |> unnest_legacy() # nesting ------------------------------------------------------------------- as_tibble(iris) |> nest_legacy(!Species) as_tibble(chickwts) |> nest_legacy(weight) # unnesting ----------------------------------------------------------------- df <- tibble( x = 1:2, y = list( tibble(z = 1), tibble(z = 3:4) ) ) df |> unnest_legacy(y) # You can also unnest multiple columns simultaneously df <- tibble( a = list(c("a", "b"), "c"), b = list(1:2, 3), c = c(11, 22) ) df |> unnest_legacy(a, b) # If you omit the column names, it'll unnest all list-cols df |> unnest_legacy()Packing and unpacking preserve the length of a data frame, changing its width. pack() makes df narrow by collapsing a set of columns into a single df-column. unpack() makes data wider by expanding df-columns back out into individual columns.
pack(.data, ..., .names_sep = NULL, .error_call = current_env()) unpack( data, cols, ..., names_sep = NULL, names_repair = "check_unique", error_call = current_env() )# Packing ------------------------------------------------------------------- # It's not currently clear why you would ever want to pack columns # since few functions work with this sort of data. df <- tibble(x1 = 1:3, x2 = 4:6, x3 = 7:9, y = 1:3) df df |> pack(x = starts_with("x")) df |> pack(x = c(x1, x2, x3), y = y) # .names_sep allows you to strip off common prefixes; this # acts as a natural inverse to name_sep in unpack() iris |> as_tibble() |> pack( Sepal = starts_with("Sepal"), Petal = starts_with("Petal"), .names_sep = "." ) # Unpacking ----------------------------------------------------------------- df <- tibble( x = 1:3, y = tibble(a = 1:3, b = 3:1), z = tibble(X = c("a", "b", "c"), Y = runif(3), Z = c(TRUE, FALSE, NA)) ) df df |> unpack(y) df |> unpack(c(y, z)) df |> unpack(c(y, z), names_sep = "_")pivot_longer() "lengthens" data, increasing the number of rows and decreasing the number of columns. The inverse transformation is [=pivot_wider]pivot_wider() Learn more in vignette("pivot").
pivot_longer( data, cols, ..., cols_vary = "fastest", names_to = "name", names_prefix = NULL, names_sep = NULL, names_pattern = NULL, names_ptypes = NULL, names_transform = NULL, names_repair = "check_unique", values_to = "value", values_drop_na = FALSE, values_ptypes = NULL, values_transform = NULL )# See vignette("pivot") for examples and explanation # Simplest case where column names are character data relig_income relig_income |> pivot_longer(!religion, names_to = "income", values_to = "count") # Slightly more complex case where columns have common prefix, # and missing missings are structural so should be dropped. billboard billboard |> pivot_longer( cols = starts_with("wk"), names_to = "week", names_prefix = "wk", values_to = "rank", values_drop_na = TRUE ) # Multiple variables stored in column names who |> pivot_longer( cols = new_sp_m014:newrel_f65, names_to = c("diagnosis", "gender", "age"), names_pattern = "new_?(.*)_(.)(.*)", values_to = "count" ) # Multiple observations per row. Since all columns are used in the pivoting # process, we'll use `cols_vary` to keep values from the original columns # close together in the output. anscombe anscombe |> pivot_longer( everything(), cols_vary = "slowest", names_to = c(".value", "set"), names_pattern = "(.)(.)" )This is a low level interface to pivoting, inspired by the cdata package, that allows you to describe pivoting with a data frame.
pivot_longer_spec( data, spec, ..., cols_vary = "fastest", names_repair = "check_unique", values_drop_na = FALSE, values_ptypes = NULL, values_transform = NULL, error_call = current_env() ) build_longer_spec( data, cols, ..., names_to = "name", values_to = "value", names_prefix = NULL, names_sep = NULL, names_pattern = NULL, names_ptypes = NULL, names_transform = NULL, error_call = current_env() )# See vignette("pivot") for examples and explanation # Use `build_longer_spec()` to build `spec` using similar syntax to `pivot_longer()` # and run `pivot_longer_spec()` based on `spec`. spec <- relig_income |> build_longer_spec( cols = !religion, names_to = "income", values_to = "count" ) spec pivot_longer_spec(relig_income, spec) # Is equivalent to: relig_income |> pivot_longer( cols = !religion, names_to = "income", values_to = "count" )pivot_wider() "widens" data, increasing the number of columns and decreasing the number of rows. The inverse transformation is [=pivot_longer]pivot_longer(). Learn more in vignette("pivot").
pivot_wider( data, ..., id_cols = NULL, id_expand = FALSE, names_from = name, names_prefix = "", names_sep = "_", names_glue = NULL, names_sort = FALSE, names_vary = "fastest", names_expand = FALSE, names_repair = "check_unique", values_from = value, values_fill = NULL, values_fn = NULL, unused_fn = NULL )# See vignette("pivot") for examples and explanation fish_encounters fish_encounters |> pivot_wider(names_from = station, values_from = seen) # Fill in missing values fish_encounters |> pivot_wider(names_from = station, values_from = seen, values_fill = 0) # Generate column names from multiple variables us_rent_income us_rent_income |> pivot_wider( names_from = variable, values_from = c(estimate, moe) ) # You can control whether `names_from` values vary fastest or slowest # relative to the `values_from` column names using `names_vary`. us_rent_income |> pivot_wider( names_from = variable, values_from = c(estimate, moe), names_vary = "slowest" ) # When there are multiple `names_from` or `values_from`, you can use # use `names_sep` or `names_glue` to control the output variable names us_rent_income |> pivot_wider( names_from = variable, names_sep = ".", values_from = c(estimate, moe) ) us_rent_income |> pivot_wider( names_from = variable, names_glue = "variable_.value", values_from = c(estimate, moe) ) # Can perform aggregation with `values_fn` warpbreaks <- as_tibble(warpbreaks[c("wool", "tension", "breaks")]) warpbreaks warpbreaks |> pivot_wider( names_from = wool, values_from = breaks, values_fn = mean ) # Can pass an anonymous function to `values_fn` when you # need to supply additional arguments warpbreaks$breaks[1] <- NA warpbreaks |> pivot_wider( names_from = wool, values_from = breaks, values_fn = ~ mean(.x, na.rm = TRUE) )This is a low level interface to pivoting, inspired by the cdata package, that allows you to describe pivoting with a data frame.
pivot_wider_spec( data, spec, ..., names_repair = "check_unique", id_cols = NULL, id_expand = FALSE, values_fill = NULL, values_fn = NULL, unused_fn = NULL, error_call = current_env() ) build_wider_spec( data, ..., names_from = name, values_from = value, names_prefix = "", names_sep = "_", names_glue = NULL, names_sort = FALSE, names_vary = "fastest", names_expand = FALSE, error_call = current_env() )# See vignette("pivot") for examples and explanation us_rent_income spec1 <- us_rent_income |> build_wider_spec(names_from = variable, values_from = c(estimate, moe)) spec1 us_rent_income |> pivot_wider_spec(spec1) # Is equivalent to us_rent_income |> pivot_wider(names_from = variable, values_from = c(estimate, moe)) # `pivot_wider_spec()` provides more control over column names and output format # instead of creating columns with estimate_ and moe_ prefixes, # keep original variable name for estimates and attach _moe as suffix spec2 <- tibble( .name = c("income", "rent", "income_moe", "rent_moe"), .value = c("estimate", "estimate", "moe", "moe"), variable = c("income", "rent", "income", "rent") ) us_rent_income |> pivot_wider_spec(spec2)These objects are imported from other packages. Follow the links below to see their documentation. tibble[tibble]as_tibble, [tibble]tibble, [tibble]tribble tidyselect[tidyselect]all_of, [tidyselect:all_of]any_of, [tidyselect:starts_with]contains, [tidyselect:starts_with]ends_with, [tidyselect]everything, [tidyselect:everything]last_col, [tidyselect:starts_with]matches, [tidyselect:starts_with]num_range, [tidyselect]one_of, [tidyselect]starts_with
Pew religion and income survey
relig_incomeDownloaded from https://www.pewresearch.org/religious-landscape-study/database/ (downloaded November 2009)Replace NAs with specified values
replace_na(data, replace, ...)# Replace NAs in a data frame df <- tibble(x = c(1, 2, NA), y = c("a", NA, "b")) df |> replace_na(list(x = 0, y = "unknown")) # Replace NAs in a vector df |> dplyr::mutate(x = replace_na(x, 0)) # OR df$x |> replace_na(0) df$y |> replace_na("unknown") # Replace NULLs in a list: NULLs are the list-col equivalent of NAs df_list <- tibble(z = list(1:5, NULL, 10:20)) df_list |> replace_na(list(z = list(5)))htmlhttps://lifecycle.r-lib.org/articles/stages.html#supersededlifecycle-superseded.svgoptions: alt='[Superseded]'[Superseded] separate() has been superseded in favour of [=separate_wider_position]separate_wider_position() and [=separate_wider_delim]separate_wider_delim() because the two functions make the two uses more obvious, the API is more polished, and the handling of problems is better. Superseded functions will not go away, but will only receive critical bug fixes. Given either a regular expression or a vector of character positions, separate() turns a single character column into multiple columns.
separate( data, col, into, sep = "[^[:alnum:]]+", remove = TRUE, convert = FALSE, extra = "warn", fill = "warn", ... )# If you want to split by any non-alphanumeric value (the default): df <- tibble(x = c(NA, "x.y", "x.z", "y.z")) df |> separate(x, c("A", "B")) # If you just want the second variable: df |> separate(x, c(NA, "B")) # We now recommend separate_wider_delim() instead: df |> separate_wider_delim(x, ".", names = c("A", "B")) df |> separate_wider_delim(x, ".", names = c(NA, "B")) # Controlling uneven splits ------------------------------------------------- # If every row doesn't split into the same number of pieces, use # the extra and fill arguments to control what happens: df <- tibble(x = c("x", "x y", "x y z", NA)) df |> separate(x, c("a", "b")) # The same behaviour as previous, but drops the c without warnings: df |> separate(x, c("a", "b"), extra = "drop", fill = "right") # Opposite of previous, keeping the c and filling left: df |> separate(x, c("a", "b"), extra = "merge", fill = "left") # Or you can keep all three: df |> separate(x, c("a", "b", "c")) # To only split a specified number of times use extra = "merge": df <- tibble(x = c("x: 123", "y: error: 7")) df |> separate(x, c("key", "value"), ": ", extra = "merge") # Controlling column types -------------------------------------------------- # convert = TRUE detects column classes: df <- tibble(x = c("x:1", "x:2", "y:4", "z", NA)) df |> separate(x, c("key", "value"), ":") |> str() df |> separate(x, c("key", "value"), ":", convert = TRUE) |> str()htmlhttps://lifecycle.r-lib.org/articles/stages.html#experimentallifecycle-experimental.svgoptions: alt='[Experimental]'[Experimental] Each of these functions takes a string and splits it into multiple rows: separate_longer_delim() splits by a delimiter. separate_longer_position() splits by a fixed width.
separate_longer_delim(data, cols, delim, ...) separate_longer_position(data, cols, width, ..., keep_empty = FALSE)df <- tibble(id = 1:4, x = c("x", "x y", "x y z", NA)) df |> separate_longer_delim(x, delim = " ") # You can separate multiple columns at once if they have the same structure df <- tibble(id = 1:3, x = c("x", "x y", "x y z"), y = c("a", "a b", "a b c")) df |> separate_longer_delim(c(x, y), delim = " ") # Or instead split by a fixed length df <- tibble(id = 1:3, x = c("ab", "def", "")) df |> separate_longer_position(x, 1) df |> separate_longer_position(x, 2) df |> separate_longer_position(x, 2, keep_empty = TRUE)htmlhttps://lifecycle.r-lib.org/articles/stages.html#supersededlifecycle-superseded.svgoptions: alt='[Superseded]'[Superseded] separate_rows() has been superseded in favour of [=separate_longer_delim]separate_longer_delim() because it has a more consistent API with other separate functions. Superseded functions will not go away, but will only receive critical bug fixes. If a variable contains observations with multiple delimited values, separate_rows() separates the values and places each one in its own row.
separate_rows(data, ..., sep = "[^[:alnum:].]+", convert = FALSE)df <- tibble( x = 1:3, y = c("a", "d,e,f", "g,h"), z = c("1", "2,3,4", "5,6") ) separate_rows(df, y, z, convert = TRUE) # Now recommended df |> separate_longer_delim(c(y, z), delim = ",")htmlhttps://lifecycle.r-lib.org/articles/stages.html#experimentallifecycle-experimental.svgoptions: alt='[Experimental]'[Experimental] Each of these functions takes a string column and splits it into multiple new columns: separate_wider_delim() splits by delimiter. separate_wider_position() splits at fixed widths. separate_wider_regex() splits with regular expression matches. These functions are equivalent to [=separate]separate() and [=extract]extract(), but use https://stringr.tidyverse.org/stringr as the underlying string manipulation engine, and their interfaces reflect what we've learned from [=unnest_wider]unnest_wider() and [=unnest_longer]unnest_longer().
separate_wider_delim( data, cols, delim, ..., names = NULL, names_sep = NULL, names_repair = "check_unique", too_few = c("error", "debug", "align_start", "align_end"), too_many = c("error", "debug", "drop", "merge"), cols_remove = TRUE ) separate_wider_position( data, cols, widths, ..., names_sep = NULL, names_repair = "check_unique", too_few = c("error", "debug", "align_start"), too_many = c("error", "debug", "drop"), cols_remove = TRUE ) separate_wider_regex( data, cols, patterns, ..., names_sep = NULL, names_repair = "check_unique", too_few = c("error", "debug", "align_start"), cols_remove = TRUE )df <- tibble(id = 1:3, x = c("m-123", "f-455", "f-123")) # There are three basic ways to split up a string into pieces: # 1. with a delimiter df |> separate_wider_delim(x, delim = "-", names = c("gender", "unit")) # 2. by length df |> separate_wider_position(x, c(gender = 1, 1, unit = 3)) # 3. defining each component with a regular expression df |> separate_wider_regex(x, c(gender = ".", ".", unit = "\\\+")) # Sometimes you split on the "last" delimiter df <- tibble(var = c("race_1", "race_2", "age_bucket_1", "age_bucket_2")) # _delim won't help because it always splits on the first delimiter try(df |> separate_wider_delim(var, "_", names = c("var1", "var2"))) df |> separate_wider_delim(var, "_", names = c("var1", "var2"), too_many = "merge") # Instead, you can use _regex df |> separate_wider_regex(var, c(var1 = ".*", "_", var2 = ".*")) # this works because * is greedy; you can mimic the _delim behaviour with .*? df |> separate_wider_regex(var, c(var1 = ".*?", "_", var2 = ".*")) # If the number of components varies, it's most natural to split into rows df <- tibble(id = 1:4, x = c("x", "x y", "x y z", NA)) df |> separate_longer_delim(x, delim = " ") # But separate_wider_delim() provides some tools to deal with the problem # The default behaviour tells you that there's a problem try(df |> separate_wider_delim(x, delim = " ", names = c("a", "b"))) # You can get additional insight by using the debug options df |> separate_wider_delim( x, delim = " ", names = c("a", "b"), too_few = "debug", too_many = "debug" ) # But you can suppress the warnings df |> separate_wider_delim( x, delim = " ", names = c("a", "b"), too_few = "align_start", too_many = "merge" ) # Or choose to automatically name the columns, producing as many as needed df |> separate_wider_delim(x, delim = " ", names_sep = "", too_few = "align_start")A small demo dataset describing John and Mary Smith.
smithshtmlhttps://lifecycle.r-lib.org/articles/stages.html#supersededlifecycle-superseded.svgoptions: alt='[Superseded]'[Superseded] Development on spread() is complete, and for new code we recommend switching to pivot_wider(), which is easier to use, more featureful, and still under active development. df |> spread(key, value) is equivalent to df |> pivot_wider(names_from = key, values_from = value) See more details in vignette("pivot").
spread(data, key, value, fill = NA, convert = FALSE, drop = TRUE, sep = NULL)stocks <- tibble( time = as.Date("2009-01-01") + 0:9, X = rnorm(10, 0, 1), Y = rnorm(10, 0, 2), Z = rnorm(10, 0, 4) ) stocksm <- stocks |> gather(stock, price, -time) stocksm |> spread(stock, price) stocksm |> spread(time, price) # Spread and gather are complements df <- tibble(x = c("a", "b"), y = c(3, 4), z = c(5, 6)) df |> spread(x, y) |> gather("x", "y", a:b, na.rm = TRUE) # Use 'convert = TRUE' to produce variables of mixed type df <- tibble( row = rep(c(1, 51), each = 3), var = rep(c("Sepal.Length", "Species", "Species_num"), 2), value = c(5.1, "setosa", 1, 7.0, "versicolor", 2) ) df |> spread(var, value) |> str() df |> spread(var, value, convert = TRUE) |> str()Data sets that demonstrate multiple ways to layout the same tabular data.
table1 table2 table3 table4a table4b table5https://www.who.int/teams/global-tuberculosis-programme/datahtmllogo.pngoptions: style='float: right' alt='logo' width='120' Tools to help to create tidy data, where each column is a variable, each row is an observation, and each cell contains a single value. 'tidyr' contains tools for changing the shape (pivoting) and hierarchy (nesting and 'unnesting') of a dataset, turning deeply nested lists into rectangular data frames ('rectangling'), and extracting values out of string columns. It also includes tools for working with missing values (both implicit and explicit).
This page describes the <data-masking> argument modifier which indicates that the argument uses data masking, a sub-type of tidy evaluation. If you've never heard of tidy evaluation before, start with the practical introduction in https://r4ds.hadley.nz/functions.html#data-frame-functions then then read more about the underlying theory in https://rlang.r-lib.org/reference/topic-data-mask.html.
Ensures all column names are unique using the approach found in tidyr 0.8.3 and earlier. Only use this function if you want to preserve the naming strategy, otherwise you're better off adopting the new tidyverse standard with name_repair = "universal"
tidyr_legacy(nms, prefix = "V", sep = "")df <- tibble(x = 1:2, y = list(tibble(x = 3:5), tibble(x = 4:7))) # Doesn't work because it would produce a data frame with two # columns called x unnest(df, y) # The new tidyverse standard: unnest(df, y, names_repair = "universal") # The old tidyr approach unnest(df, y, names_repair = tidyr_legacy)This page describes the <tidy-select> argument modifier which indicates that the argument uses tidy selection, a sub-type of tidy evaluation. If you've never heard of tidy evaluation before, start with the practical introduction in https://r4ds.hadley.nz/functions.html#data-frame-functions then then read more about the underlying theory in https://rlang.r-lib.org/reference/topic-data-mask.html.
Performs the opposite operation to [dplyr:count]dplyr::count(), duplicating rows according to a weighting variable (or expression).
uncount(data, weights, ..., .remove = TRUE, .id = NULL)df <- tibble(x = c("a", "b"), n = c(1, 2)) uncount(df, n) uncount(df, n, .id = "id") # You can also use constants uncount(df, 2) # Or expressions uncount(df, 2 / n)Convenience function to paste together multiple columns into one.
unite(data, col, ..., sep = "_", remove = TRUE, na.rm = FALSE)df <- expand_grid(x = c("a", NA), y = c("b", NA)) df df |> unite("z", x:y, remove = FALSE) # To remove missing values: df |> unite("z", x:y, na.rm = TRUE, remove = FALSE) # Separate is almost the complement of unite df |> unite("xy", x:y) |> separate(xy, c("x", "y")) # (but note `x` and `y` contain now "NA" not NA)Unnest expands a list-column containing data frames into rows and columns.
unnest( data, cols, ..., keep_empty = FALSE, ptype = NULL, names_sep = NULL, names_repair = "check_unique", .drop = deprecated(), .id = deprecated(), .sep = deprecated(), .preserve = deprecated() )# unnest() is designed to work with lists of data frames df <- tibble( x = 1:3, y = list( NULL, tibble(a = 1, b = 2), tibble(a = 1:3, b = 3:1, c = 4) ) ) # unnest() recycles input rows for each row of the list-column # and adds a column for each column df |> unnest(y) # input rows with 0 rows in the list-column will usually disappear, # but you can keep them (generating NAs) with keep_empty = TRUE: df |> unnest(y, keep_empty = TRUE) # Multiple columns ---------------------------------------------------------- # You can unnest multiple columns simultaneously df <- tibble( x = 1:2, y = list( tibble(a = 1, b = 2), tibble(a = 3:4, b = 5:6) ), z = list( tibble(c = 1, d = 2), tibble(c = 3:4, d = 5:6) ) ) df |> unnest(c(y, z)) # Compare with unnesting one column at a time, which generates # the Cartesian product df |> unnest(y) |> unnest(z)unnest_auto() picks between unnest_wider() or unnest_longer() by inspecting the inner names of the list-col: If all elements are unnamed, it uses unnest_longer(indices_include = FALSE). If all elements are named, and there's at least one name in common across all components, it uses unnest_wider(). Otherwise, it falls back to unnest_longer(indices_include = TRUE). It's handy for very rapid interactive exploration but I don't recommend using it in scripts, because it will succeed even if the underlying data radically changes.
unnest_auto(data, col)unnest_longer() turns each element of a list-column into a row. It is most naturally suited to list-columns where the elements are unnamed and the length of each element varies from row to row. unnest_longer() generally preserves the number of columns of x while modifying the number of rows. Learn more in vignette("rectangle").
unnest_longer( data, col, values_to = NULL, indices_to = NULL, indices_include = NULL, keep_empty = FALSE, names_repair = "check_unique", simplify = TRUE, ptype = NULL, transform = NULL )# `unnest_longer()` is useful when each component of the list should # form a row df <- tibble( x = 1:4, y = list(NULL, 1:3, 4:5, integer()) ) df |> unnest_longer(y) # Note that empty values like `NULL` and `integer()` are dropped by # default. If you'd like to keep them, set `keep_empty = TRUE`. df |> unnest_longer(y, keep_empty = TRUE) # If the inner vectors are named, the names are copied to an `_id` column df <- tibble( x = 1:2, y = list(c(a = 1, b = 2), c(a = 10, b = 11, c = 12)) ) df |> unnest_longer(y) # Multiple columns ---------------------------------------------------------- # If columns are aligned, you can unnest simultaneously df <- tibble( x = 1:2, y = list(1:2, 3:4), z = list(5:6, 7:8) ) df |> unnest_longer(c(y, z)) # This is important because sequential unnesting would generate the # Cartesian product of the rows df |> unnest_longer(y) |> unnest_longer(z)unnest_wider() turns each element of a list-column into a column. It is most naturally suited to list-columns where every element is named, and the names are consistent from row-to-row. unnest_wider() preserves the rows of x while modifying the columns. Learn more in vignette("rectangle").
unnest_wider( data, col, names_sep = NULL, simplify = TRUE, strict = FALSE, names_repair = "check_unique", ptype = NULL, transform = NULL )df <- tibble( character = c("Toothless", "Dory"), metadata = list( list( species = "dragon", color = "black", films = c( "How to Train Your Dragon", "How to Train Your Dragon 2", "How to Train Your Dragon: The Hidden World" ) ), list( species = "blue tang", color = "blue", films = c("Finding Nemo", "Finding Dory") ) ) ) df # Turn all components of metadata into columns df |> unnest_wider(metadata) # Choose not to simplify list-cols of length-1 elements df |> unnest_wider(metadata, simplify = FALSE) df |> unnest_wider(metadata, simplify = list(color = FALSE)) # You can also widen unnamed list-cols: df <- tibble( x = 1:3, y = list(NULL, 1:3, 4:5) ) # but you must supply `names_sep` to do so, which generates automatic names: df |> unnest_wider(y, names_sep = "_") # 0-length elements --------------------------------------------------------- # The defaults of `unnest_wider()` treat empty types (like `list()`) as `NULL`. json <- list( list(x = 1:2, y = 1:2), list(x = list(), y = 3:4), list(x = 3L, y = list()) ) df <- tibble(json = json) df |> unnest_wider(json) # To instead enforce strict vctrs typing rules, use `strict` df |> unnest_wider(json, strict = TRUE)Captured from the 2017 American Community Survey using the tidycensus package.
us_rent_incomeA subset of data from the World Health Organization Global Tuberculosis Report, and accompanying global populations. who uses the original codes from the World Health Organization. The column names for columns 5 through 60 are made by combining new_ with: the method of diagnosis (rel = relapse, sn = negative pulmonary smear, sp = positive pulmonary smear, ep = extrapulmonary), gender (f = female, m = male), and age group (014 = 0-14 yrs of age, 1524 = 15-24, 2534 = 25-34, 3544 = 35-44 years of age, 4554 = 45-54, 5564 = 55-64, 65 = 65 years or older). who2 is a lightly modified version that makes teaching the basics easier by tweaking the variables to be slightly more consistent and dropping iso2 and iso3. newrel is replaced by new_rel, and a _ is added after the gender.
who who2 populationhttps://www.who.int/teams/global-tuberculosis-programme/dataData about population from the World Bank.
world_bank_popDataset from the World Bank data bank: https://data.worldbank.org| Repository | Version | Published | First seen | Last seen | Docs |
|---|---|---|---|---|---|
| CRAN | 1.3.2 | 2026-05-29 | 2026-05-30 | ||
| R-universe | 1.3.2.9000 | 2026-05-29 | 2026-05-30 |
표시할 OSV 데이터가 없습니다.
표시할 OpenAlex 데이터가 없습니다.