Questions tagged [tidyr]

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. tidyr is the successor to reshape2.

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

Links:

4200 questions
1
vote
1 answer

Why is the unite function not accepting my column names?

I'm baffled. This code will not work for my dataset, but it works fine with dummy data. As far as I can tell there is no important differences in the structure of these two datasets. Why might I be getting this error about undefined columns? >…
canderson156
  • 1,045
  • 10
  • 24
1
vote
3 answers

Fill NA with a series of characters in R dplyr

I have a large data frame that looks like this. Each player is assigned to a group. library(tidyverse) df <- tibble(player=c(1,2,3,4,5),groups=c("group1","group2","group2",NA,NA)) df #> # A tibble: 5 × 2 #> player groups #> #> 1 …
LDT
  • 2,856
  • 2
  • 15
  • 32
1
vote
1 answer

Convert list of character vectors to tidy data frame

I have a list of character vectors that I would like to convert into a tidy data frame. The lengths of the character vectors are unequal. dput(data) list(`ko03008 Ribosome biogenesis in eukaryotes` = c("G5382", "G13330", "G4043", "G13255"),…
Alex
  • 261
  • 2
  • 5
  • 11
1
vote
2 answers

Compare multiple pairs of x/y columns after left join and if different use y in R

I have a data.frame df1. Some selected rows have been manually reviewed and updated, creating a second data.frame df1updated which has all the same columns, where some of the data has been changed, plus additional columns. I want to join the updated…
Mark Davies
  • 787
  • 5
  • 18
1
vote
2 answers

Conditionally Separate String into Columns

It is common in surveys to ask a question and then tell participants to "select all that apply". For example, "Which foods do you enjoy eating (Please select all that apply)?" a) Sushi, b) Pasta, c) Hamburger. Assuming four (N=4) participants…
EDennnis
  • 191
  • 1
  • 11
1
vote
2 answers

R crashes when using tidyr::unnest_wider

Running tidyr::unnest_wider as part of a pipe, e.g. df <- df %>% unnest_wider(col, names_sep = "_", names_repair = "universal") R crashes with the following error reported, [91205:91206:20220410,071753.955164:ERROR file_io_posix.cc:148] open…
Matt Nolan
  • 610
  • 6
  • 22
1
vote
2 answers

Use `pivot_longer` to turn a 1x4 table into a 2x2 one

I have a 1-by-4 table that contains summary statistics of two variables. For example, df <- data.frame( x_min=1, x_max=2, y_min=3, y_max=4) df x_min x_max y_min y_max 1 1 2 3 4 I'd like to shape it into a 2-by-2 format: …
Herr K.
  • 1,063
  • 7
  • 11
1
vote
2 answers

Struggling to unnest tibble (dput, code, and error included) in r

I'm trying to unnest a species count tibble so I can turn it into a dataframe. The last four columns are species counts and are currently in 'list' form (seems nested?). I'd like to have each column and row for these last four species columns to…
1
vote
4 answers

Fill Columns with TRUE or FALSE based on other Dataframe

Unfortunately I have a problem and would have to ask for your support. I have a list of the most popular pet names. From the dataframe x, it appears that "Jerry" is the most popular mouse name, "Garfield" is the second most popular cat name, and so…
RKF
  • 131
  • 7
1
vote
1 answer

Merge multiple columns with X repeating attributes into X columns

I have a dataframe arranged like below, columns are separated by months (enero, febrero, marzo, etc.) and every row corresponds to a value that I need to extract from the time series. Each pair of Month/Caudal varies in size depending of the amount…
1
vote
1 answer

group_by and fill specific rows based on capitalised row observations

I have some data which looks like: # A tibble: 10 × 4 RegionName `Año 2004_1` `Año 2004_2` `Año 2004_3` 1 ANDALUCÍA NA NA NA 2 Almería NA …
user113156
  • 6,761
  • 5
  • 35
  • 81
1
vote
2 answers

How to efficiently run many logistic regressions in R and skip over equations that throw errors?

As a continuation from this question, I want to run many logistic regression equations at once and then note if a group was significantly different from a reference group. This solution works, but it only works when I'm not missing values. Being…
J.Sabree
  • 2,280
  • 19
  • 48
1
vote
4 answers

Aggregate and summarise character object with R

I have a breeding productivity dataset: df1 # Nest.box Obs.type individual.number Clutch Chick.status # 1 Nest1 Egg 1 First NA # 2 Nest1 Egg 2 First NA # 3 Nest1 Egg 3 First NA # 4 Nest2 Egg 1 First NA # 5 Nest2 Egg 2 First…
Andre230
  • 145
  • 1
  • 9
1
vote
1 answer

r retain rows only if non missing in specific column

My dataframe has columns and rows like this Id Date Col1 Col2 Col3 X1 1 1/1/22 NA 1 0 1 1/1/22 0 0 1 6 2 5/7/21 0 1 0 2 5/7/21 0 2 0…
1
vote
1 answer

How to combine multiple rows into 1 row in R?

I am having trouble combining multiple rows into 1 row, below is my current data: I want one row of symptoms for each VAERS_ID. However, because the number of rows each VAERS_ID is inconsistent, I am having trouble. I have tried this: test= data…