Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Tidy Messy Data

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md
NotificationsYou must be signed in to change notification settings

tidyverse/tidyr

CRAN statusR-CMD-checkCodecov test coverage

Overview

The goal of tidyr is to help you createtidy data. Tidy data is datawhere:

  1. Each variable is a column; each column is a variable.
  2. Each observation is a row; each row is an observation.
  3. Each value is a cell; each cell is a single value.

Tidy data describes a standard way of storing data that is used whereverpossible throughout thetidyverse. If youensure that your data is tidy, you’ll spend less time fighting with thetools and more time working on your analysis. Learn more about tidy datainvignette("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.0introducespivot_longer() andpivot_wider(), replacing the olderspread() andgather() functions. Seevignette("pivot") for moredetails.

  • “Rectangling”, which turns deeply nested lists (as from JSON) intotidy tibbles. Seeunnest_longer(),unnest_wider(),hoist(), andvignette("rectangle") for more details.

  • Nesting converts grouped data to a form where each group becomes asingle row containing a nested data frame, and unnesting does theopposite. Seenest(),unnest(), andvignette("nest") for moredetails.

  • Splitting and combining character columns. Useseparate_wider_delim(),separate_wider_position(), andseparate_wider_regex() to pull a single character column intomultiple columns; useunite() to combine multiple columns into asingle character column.

  • Make implicit missing values explicit withcomplete(); make explicitmissing values implicit withdrop_na(); replace missing values withnext/previous value withfill(), or a known value withreplace_na().

Related work

tidyrsupersedesreshape2 (2010-2014) and reshape (2005-2010). Somewhatcounterintuitively, each iteration of the package has done less. tidyris designed specifically for tidying data, not general reshaping(reshape2), or the general aggregation (reshape).

data.table provideshigh-performance implementations ofmelt() anddcast()

If you’d like to read more about data reshaping from a CS perspective,I’d recommend the following three papers:

To guide your reading, here’s a translation between the terminology usedin different places:

tidyr 1.0.0pivot longerpivot wider
tidyr < 1.0.0gatherspread
reshape(2)meltcast
spreadsheetsunpivotpivot
databasesfoldunfold

Getting help

If you encounter a clear bug, please file a minimal reproducible exampleongithub. For questionsand other discussion, please useforum.posit.co.


Please note that the tidyr project is released with aContributor Codeof Conduct. Bycontributing to this project, you agree to abide by its terms.

About

Tidy Messy Data

Topics

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md

Code of conduct

Contributing

Stars

Watchers

Forks

Contributors136

Languages


[8]ページ先頭

©2009-2025 Movatter.jp