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

How to separate "." delimited columns with tidyR

I think I am missing something important. Every time I am trying to separate a column which has "." delimiter I fail. Does anyone have an idea why? library(tidyverse) library(reprex) check=data.frame(time=c("1.2","1.3"),light=c("A","B")) check #> …
LDT
  • 2,856
  • 2
  • 15
  • 32
1
vote
1 answer

Count number of utterances by same speakers but discount number of in-between pauses

In this data of Speakers and their Utterances: df <- data.frame( Line = 1:15, Speaker = c("ID01.A", NA, "ID01.B", "ID17.A", NA, "ID27.B", NA, "ID27.B",…
Chris Ruehlemann
  • 20,321
  • 4
  • 12
  • 34
1
vote
1 answer

How to use complete to fill dates of two consecutive year e.g. 2021 and 2022

I have this dataframe: DF <- tribble( ~date, ~value, "2021-12-01", 1, "2022-01-01", 2) date value 1 2021-12-01 1 2 2022-01-01 2 Usually I use complete to fill each month with all days: Here I use again…
TarJae
  • 72,363
  • 6
  • 19
  • 66
1
vote
1 answer

Using `pivot_longer with` `values_ptypes` in R

My question is simple: I've been trying to use pivot_longer with values_ptypes: This is my code: df <-mtcars %>% rownames_to_column() df[1,] %>% pivot_longer(everything(),names_to = 'My Values', values_ptypes = list(rowname = 'character')) df[1,]…
Laura
  • 675
  • 10
  • 32
1
vote
1 answer

Getting extensive summary from group_by and summary

I want to find out how long the median time from last vaccine till admission to ICU is. I have a dataset looking like this: ID <- c(1:20) Group <- c("1. vacc + unvacc", "2. vacc", "3. vacc", "1. vacc + unvacc", "2. vacc", "3. vacc", "1. vacc +…
Nick Meier
  • 33
  • 4
1
vote
1 answer

pivot multiple sets of columns at once

I have a data frame where I have regressed a bunch of datasets, then taken subsets of those datasets and regressed again. This has resulted in a dataframe with columns showing the slope and intercept and standard error of the "full" dataset, then…
Jake L
  • 987
  • 9
  • 21
1
vote
2 answers

How to translate `recipes::step_dummy()` to `dplyr`/`tidyr` code?

I'm trying to figure out how step_dummy() from recipes package wrangles the data. Although there's a reference page for this function, I'm still unable to wrap my head around how to do it using "regular" tidyverse tools I know. Here's some code…
Emman
  • 3,695
  • 2
  • 20
  • 44
1
vote
3 answers

How do I create a column based on values in another column which are the names of variables in my dataframe whose data I want to fill newcol with? R

I apologize if the articulation of my question is confusing, I haven't been able to find similar threads which clarify the English of my question. I am working with a sample of data which resembles that seen…
nlplearner
  • 115
  • 1
  • 10
1
vote
3 answers

How to pivot wider multiple columns on dataset and maintain a specific colum order?

My initial dataset df1 <- structure(list(id = c(1, 1, 2, 3, 3, 3), name = c("james", "james", "peter", "anne", "anne", "anne"), trip_id = c(10,11,10,30,11,32), date =…
Andres Mora
  • 1,040
  • 8
  • 16
1
vote
2 answers

Define separator in "separate" function or use alternative

I`m trying to transform a column into multiple columns. This is my example: df <- data.frame(Id = c(1,2,3), Col2 = c("['aaa' 'aaa aaaa' 'aaa.bb']","['aaa' 'aaa aaa' 'aaa bbb ccc' 'aaa'\n]","[]")) df Id Col2 1 ['aaa' 'aaa…
RitaM
  • 143
  • 1
  • 6
1
vote
2 answers

Using tidyr::separate with quoted values containing delimiter

I have a fairly straight forward question & i'm hoping there's a very simple answer that I just haven't stumbled upon yet. I'm attempting to use tidyr::separate() to create two columns within a data.frame from a single character string column (using…
kostr
  • 836
  • 7
  • 13
1
vote
2 answers

Convert wide data to long format for repeated measures/mixed models

Currently I have data in this "wide" format: |Participant|Banana|Apple|Orange| |-|-|-|-| |P1|0|0|0| |P2|1|1|1| |P3|0|0|0| Ideally, I want to convert these data to long format for mixed models,…
vesalius
  • 27
  • 4
1
vote
3 answers

pivot_wider dissolves arrange

I try to sort each row alphabetically (in order to solve this question Reshaping a dataframe in R by sorting just some fields in a row alphabetically: This is the dataframe: df <- structure(list(ALT_1 = c("GAT", "TGC", "AGC", "T"), ALT_2 = c("CAG",…
TarJae
  • 72,363
  • 6
  • 19
  • 66
1
vote
1 answer

Need solution for recoding large number of variables

I have a dataset with the English and Spanish version of a questionnaire. The questionnaires ask whether individuals have ever received a large number of different diagnoses. Each variable takes the form prev_dx_major_depression for the English data…
1
vote
5 answers

Filling in missing NA based upon factor level

I have been trying to convert my data from a vertical configuration to a horizontal configuratoin. Using spread (), I have managed to get it in the following structure: plot, x1, x2, x3, x4, x5, x6, x7 1 0.06011071 NA NA NA NA NA NA 1 NA …
McPauwl
  • 13
  • 2
1 2 3
99
100