Top "Tidyr" questions

tidyr is an R package by Hadley Wickham for cleaning and reshaping data, designed to use the magrittr pipe (%>%) so as to interact well with dplyr and similar pipeable packages which emphasize tidy data.

Comparing gather (tidyr) to melt (reshape2)

I love the reshape2 package because it made life so doggone easy. Typically Hadley has made improvements in his previous …

r reshape2 tidyr
How to spread columns with duplicate identifiers?

A have the following tibble: structure(list(age = c("21", "17", "32", "29", "15"), gender = structure(c(2L, 1L, 1L, 2L, 2L), .Label = c("Female", "…

r tidyr
Retain attributes when using gather from tidyr (attributes are not identical)

I have a data frame that needs to be split into two tables to satisfy Codd's 3rd normal form. In …

r tidyr
Reshaping multiple sets of measurement columns (wide format) into single columns (long format)

I have a dataframe in a wide format, with repeated measurements taken within different date ranges. In my example there …

r reshape tidyr reshape2 r-faq
How to use the spread function properly in tidyr

How do I change the following table from: Type Name Answer n TypeA Apple Yes 5 TypeA Apple No 10 TypeA Apple …

r dplyr tidyr spread
Spread with data.frame/tibble with duplicate identifiers

The documentation for tidyr suggests that gather and spread are transitive, but the following example with the "iris" data shows …

r tidyr
Proper idiom for adding zero count rows in tidyr/dplyr

Suppose I have some count data that looks like this: library(tidyr) library(dplyr) X.raw <- data.frame( …

r dplyr tidyr
gather with tidyr: position must be between 0 and n error

I have some data like below: x.row10 <- setNames(data.frame(letters[1:3],1:3,2:4,3:5,4:6,5:7,6:8,7:9), c("names",2004:2009,2012)) # names 2004 2005 2006 2007 2008 2009 2012 #1 a 1 2 3 4 5 6 7 #2 b 2 3 4 5 6 7 8 #3 c 3 4 5 6 7 8 9 …

r tidyr
How can I spread repeated measures of multiple variables into wide format?

I'm trying to take columns that are in long format and spread them to wide format as shown below. I'd …

r tidyr
pivot_wider issue "Values in `values_from` are not uniquely identified; output will contain list-cols"

My data looks like this: # A tibble: 6 x 4 name val time x1 <chr> <dbl> <date&…

r tidyr