{"id":16273996,"url":"https://github.com/trinker/tidyr_in_a_nutshell","last_synced_at":"2025-04-08T16:14:07.508Z","repository":{"id":22380017,"uuid":"25716583","full_name":"trinker/tidyr_in_a_nutshell","owner":"trinker","description":null,"archived":false,"fork":false,"pushed_at":"2014-10-25T14:02:55.000Z","size":152,"stargazers_count":18,"open_issues_count":0,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-14T12:41:04.592Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/trinker.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-10-25T02:03:57.000Z","updated_at":"2018-05-26T14:41:58.000Z","dependencies_parsed_at":"2022-08-21T04:00:41.502Z","dependency_job_id":null,"html_url":"https://github.com/trinker/tidyr_in_a_nutshell","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trinker%2Ftidyr_in_a_nutshell","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trinker%2Ftidyr_in_a_nutshell/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trinker%2Ftidyr_in_a_nutshell/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trinker%2Ftidyr_in_a_nutshell/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/trinker","download_url":"https://codeload.github.com/trinker/tidyr_in_a_nutshell/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247878021,"owners_count":21011158,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-10T18:26:40.037Z","updated_at":"2025-04-08T16:14:07.473Z","avatar_url":"https://github.com/trinker.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"tidyr In a Nutshell\n===\n\nThis is a minimal guide, mostly for myself, to remind me of the most import tidyr functions and how they relate to **reshape2** functions that I'm familiar with. Also checkout [dplyr In a Nutshell](https://github.com/trinker/dplyr_in_a_nutshell).\n\n```{r setup, include=FALSE, echo=FALSE}\nlibrary(knitr)\nopts_chunk$set(comment=NA, tidy=FALSE, message = FALSE, warnings = FALSE)\n```\n\n# 2  Main Functions\n\nList of **tidyr** functions and the **reshape2** functions they're related to:\n\nreshape2 Function    | tidyr Function | Special Powers\n---------------------|-------------------|----------------------------\n`melt`               |  `gather`         | long format\\*\n`dcast`              |  `spread`         | wide format\\*\n\n\n\\*[Hadley notes](http://vita.had.co.nz/papers/tidy-data.pdf) these terms are imprecise but good enough for my little noodle\n\n## Arguments (when chaining)\n\n![](tidyr.png)\n\n\n# Demos\n### Some Data\n```{r}\nlibrary(tidyr); library(dplyr)\n\ndat \u003c- data.frame(\n   id = LETTERS[1:5],\n   x = sample(0:1, 5, TRUE),\n   y = sample(0:1, 5, TRUE),\n   z = sample(0:1, 5, TRUE)\n)\n\ndat\n```\n\n### gather in Action\n\n```{r}\ndat %\u003e% gather(item, scores, -c(id))\n```\n\n### spread it Back Out\n\n```{r}\ndat %\u003e% gather(item, scores, -c(id)) %\u003e%\n    spread(item, scores)\n```\n\n---\n\n# Additional Demos\n\n### gather\n\n```{r}\ndat %\u003e% gather(item, scores, x:z) \ndat %\u003e% gather(item, scores, x, y, z) \n```\n\n### spread\n\n```{r}\ndat %\u003e% gather(item, scores, -c(id)) %\u003e%\n    spread(id, scores)\n```\n\n\n```{r, echo=FALSE, eval=FALSE}\n## knitr::knit2html(\"README.Rmd\")\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrinker%2Ftidyr_in_a_nutshell","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftrinker%2Ftidyr_in_a_nutshell","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrinker%2Ftidyr_in_a_nutshell/lists"}