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.

Gather multiple sets of columns

I have data from an online survey where respondents go through a loop of questions 1-3 times. The survey software (…

r reshape dplyr qualtrics tidyr
Removing NA observations with dplyr::filter()

My data looks like this: library(tidyverse) df <- tribble( ~a, ~b, ~c, 1, 2, 3, 1, NA, 3, NA, 2, 3 ) I can remove all …

r dplyr tidyr tidyverse
R spreading multiple columns with tidyr

Take this sample variable df <- data.frame(month=rep(1:3,2), student=rep(c("Amy", "Bob"), each=3), A=c(9, 7, 6, 8, 6, 9), B=…

r dataframe dplyr tidyr
Using dplyr window functions to calculate percentiles

I have a working solution but am looking for a cleaner, more readable solution that perhaps takes advantage of some …

r dplyr tidyr
How to replace all NA in a dataframe using tidyr::replace_na?

I'm trying to fill all NAs in my data with 0's. Does anyone know how to do that using replace_…

r dplyr tidyr
Using spread with duplicate identifiers for rows

I have a long form dataframe that have multiple entries for same date and person. jj <- data.frame(…

r dplyr tidyr
dplyr summarise: Equivalent of ".drop=FALSE" to keep groups with zero length in output

When using summarise with plyr's ddply function, empty categories are dropped by default. You can change this behavior by adding .…

r dplyr plyr tidyr
Is it possible to use spread on multiple columns in tidyr similar to dcast?

I have the following dummy data: library(dplyr) library(tidyr) library(reshape2) dt <- expand.grid(Year = 1990:2014, Product=LETTERS[1:8], …

r reshape2 tidyr
How to transpose a dataframe in tidyverse?

Using basic R, I can transpose a dataframe, say mtcars, which has all columns of the same class: as.data.…

r dataframe transpose tidyr tidyverse
how spread() in tidyr handles factor levels

I was manipulating my data and found that I did something wrong at some point in the process. When I …

r spread tidyr