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

Is there a regular expression to direct columns to specific rows when using pivot_wider() in R?

The first three rows of my real data look like this; # Real data example fullname<-c("Argemone glauca", "Bacopa monnieri", "Brighamia insignis") Mean.Germ.coef_0<-c(0.31, 0.768015267, 0.555758514) Mean.Germ.coef_10<-c(0.119356725, 0.624444444,…
Dustin
  • 183
  • 7
1
vote
1 answer

Grouped regression with dplyr using different formulas

I try to transfer the problem from this post to a setting where you use different formulas in the lm() function in R. Here a basic setup to reproduce the problem: library(dplyr) library(broom) library(purrr) library(tidyr) # Generate…
timm
  • 257
  • 1
  • 10
1
vote
1 answer

Assigning new value based on a condition in R

I have data frame like this one: df<- data.frame( "Col1" = c("P1", "P1", "P1", "P2", "P2", "P2", "P3", "P3", "P3", "P3"), "Col2" = c("L", "L&R", "R", "V", "V&N", "N", "M", "I", "I&M", "I&M&G"), "Value" = c("20", "5",…
Marwah Al-kaabi
  • 419
  • 2
  • 7
1
vote
1 answer

r arrange data nested wide format

I have a dataset like this Time1 Time2 Time3 A Median 0.046 0.12 0 Q1, Q3 -0.12, 0.22 -1.67, -4.59 -0.245, 0.289 Range -2.75 -4.65 …
1
vote
2 answers

Multiply every new rows created by `separate_rows`

I am using the separate_rows function from tidyr. Essentially, I would like to change the value of the data that is copied -- in the example below, it would read: "everytime a new row is created, multiply z by 0.5" I already added an index in the…
lupo404
  • 55
  • 5
1
vote
1 answer

summarize_each but use other characters as separator

summarize_each automatically uses "_" as a separator for the variable name to tag on the function used. Is there any way to use other characters? I have gone here: choose separator for auto column names in dplyr But the issue is that I already have…
1
vote
1 answer

Transform long format dataframe with multiples sets of columns into wide format

How can you transform a long format dataframe with multiple sets of columns into a wide format? df <- data.frame( id = c(1, 2), uid = c("m1", "m2"), germ = c(23, 24), category = c("x1", "x2"), mineral = c(78, 10)) Names come from uid and…
jmutua
  • 290
  • 1
  • 12
1
vote
3 answers

How to match column value in a dataframe based on condition in another dataframe?

I have two dataframes with different number of rows, simple example below: df= data.frame(Xmin=c(10,15),Xmax=c(20,20),Ymin=c(10,20),Ymax=c(20,25),ID=c(1,2)) df Xmin Xmax Ymin Ymax ID 1 10 20 10 20 1 2 15 20 20 25 …
Kaizen
  • 131
  • 1
  • 11
1
vote
1 answer

Collapse groups according to a list of codes

I have a table of comma separated codes that should be collapsed group_codes <- tibble::tribble( ~group_codes, "AAA11, AAA1Z", "ZZZ21, ZZZ2Z" ) And a table on which the collapsing and summing should be run: tibble::tribble( ~codes,…
Jacek Kotowski
  • 620
  • 16
  • 49
1
vote
2 answers

A Tricky Pivot Longer using colname patterns

I have a dataframe like this : data.frame(id = c(1,2,3), first_value=c("A","B","NA"),second_value=c("A","NA","D"), first_date=c("2001",2010,2003),second_date=c("2003",2014,"2007")) id first_value second_values first_date…
Wael
  • 1,640
  • 1
  • 9
  • 20
1
vote
1 answer

How to merge rows of a dataframe that have the same value in a column

I have a dataframe that I have obtained after converting a long format dataframe into a wide format dataframe using tidyr::spread() The dataframe orig_dataframe = data.frame(ID = c(1,1,2,2,3,3,4,4), Name = c("","a", "", "b", "", "c", "", "d"),…
ag14
  • 867
  • 1
  • 8
  • 15
1
vote
1 answer

How can I split this date?

I am working with this dataset and I am trying to separate the 'Date' column into the day, month, and year but have run into a problem doing it because it has the month as a character value. Any help would be great. Here's an image: Dataset
EthanMcQ
  • 31
  • 4
1
vote
1 answer

R replace NA with last value for group ID ordered by date

Sample dataframe: eg_data <- data.frame( custID = c('655321' , '655321' , '655321' , '655321' , '655321' , '655321' , '655321' , '655321' , '655321' , '655321' , '655321' , '655321' , '655321', '655321' , '655321' , '655321' , …
Adam_S
  • 687
  • 2
  • 12
  • 24
1
vote
1 answer

Reshape data table from wide to long with transpose

I have a dataset (Sample_pH): Head(Sample_pH) Mill Acid `1_day` `3_days` `1_week` `2_weeks` `4_weeks` `2_months` `3_months` `6-7_months`
Nanna
  • 73
  • 8
1
vote
0 answers

combining user defined tidyverse helper and main functions for packagedevelopment in R

I would like to source an external helper function within a main function, for package development. I have provided a simplified example below with the desired results by programming in tidyverse the long way. R is producing a "problem with mutate",…
cn838
  • 69
  • 8