tidyr Questions

2

Solved

I'd like to sample rows from a data frame by group. But here's the catch, I'd like to sample a different number of records based on data from another table. Here is my reproducible data: df <- ...
Lamee asked 15/1, 2017 at 21:50

6

Solved

My data looks like this: # A tibble: 6 x 4 name val time x1 <chr> <dbl> <date> <dbl> 1 C Farolillo 7 2016-04-20 51.5 2 C Farolillo 3 2016-04-21 56.3 3 C Farolillo 7 2016-...
Judo asked 13/11, 2019 at 13:3

2

Solved

I searched and searched for this and found similar stuff but nothing quite right. Hopefully this hasn't been answered. Lets say I have a column with Y,N, and sometimes extra information df<-d...
Keto asked 22/3, 2018 at 19:31

3

Solved

I have a data.frame with ids composed of sequences of alphanumeric characters (e.g., id = c(A001, A002, B013)). I was looking for an easy function under stringr or stirngi that would easily do math...
Lobelia asked 6/12, 2018 at 21:13

4

Here is my input dataset which contains one row and 12 columns/variables: df <- data.frame(q_q10=0,q_q20=0, q_q30=0,q_q40=400, q_q10_low=0,q_q20_low=0,q_q30_low=0,q_q40_low=350, q_q10_up...
Irrelevant asked 18/10, 2023 at 12:54

2

Solved

Since the update to tidyr version 1.0.0 I have started to get an error when unnesting a list of dataframes. The error comes because some of the data frames in the list contain a column with all NA...
Corticosterone asked 11/10, 2019 at 8:36

3

Solved

I have example data like below, where for a unit, I have multiple treatments, and multiple measurements for each treatment in before and after periods. I want to do a before-after comparison, so I ...
Casebound asked 8/8, 2019 at 21:15

3

Solved

I have a dataframe with several columns containing list columns that I want to unnest (or unchop). BUT, they are different lengths, so the resulting error is Error: No common size for... Here is a...
Ventriloquism asked 5/12, 2019 at 10:6

11

Solved

I have a working solution but am looking for a cleaner, more readable solution that perhaps takes advantage of some of the newer dplyr window functions. Using the mtcars dataset, if I want to look...
Kelby asked 27/5, 2015 at 16:38

2

Solved

I have a data.frame with several columns: set.seed(1) df <- data.frame(cluster=LETTERS[1:4],group=c(rep("m",2),rep("f",2)),point=rnorm(4),err=runif(4,0.1,0.3)) and I'd add another columns whi...
Thomasthomasa asked 2/7, 2018 at 16:46

1

Solved

Given a dataframe: df <- data.frame(Col1 = LETTERS[1:4], Col2 = LETTERS[23:26], Col3 = c(1:4), col4 = c(100:103)) I want to combine column with their column names. I know I can use unite from t...
Campfire asked 22/6, 2023 at 3:52

4

Solved

Suppose I have a 3-dimensional array g with dimensions [x,y,z]. reshape2::melt(g) would produce a data frame with columns giving indices of x,y,z and value where value contains the values in each e...
Flyfish asked 25/8, 2022 at 17:4

7

Solved

I have data with columns such as Area_bsl that contain strings of comma-separated values and a column diffr that states the number of elements by which Area_bsl must be shortened: df <- data.fra...
Subirrigate asked 5/5, 2023 at 9:20

3

I would like to make a cross tab in R using dplyr. I have good reasons for not just using the base table() command. table(mtcars$cyl, mtcars$gear) 3 4 5 4 1 8 2 6 2 4 1 8 12 0 2 library(dplyr...
Melioration asked 17/3, 2015 at 19:52

6

Solved

I'm trying to preserve the order of columns when I gather them from wide to long format. The problem I'm having is after I gather and summarize the order is lost. The number of columns is huge so I...
Unhandy asked 27/10, 2017 at 18:15

4

Solved

I have a large dataset that looks like this. I was wondering if there is a clever way to apply a t-test, in each row, aka gene, and compare the counts between humans and mice. I want to compete in ...
Selene asked 15/1, 2023 at 17:45

2

Solved

I'd like to use mutate function from the tidyverse to create a new column based on the old column using only a data frame and strings, which represent column headers, as inputs. I can get this to...
Valence asked 30/3, 2018 at 14:29

2

Solved

I am a bit puzzled by separating columns using the separate function in tidyr: My data frame looks like this library(tidyverse) df=tibble(col1 = c("2397_A_run379_CTTGTACT_S119_L004_R1_001&quo...
Autotomy asked 11/11, 2022 at 10:46

3

Solved

I have a large data set (35.8 GB, over 1 billion rows) that I need to tidy. Here is some reproducible code to show its format. id <- c(1, 1, 2, 2) item <- c("a1", "a2", &q...
Taboret asked 20/10, 2022 at 0:35

3

Solved

tidyr::fill() isn't filling values in my tibble. Here is a reprex: library(tidyverse) library(googlesheets4) url <- "https://docs.google.com/spreadsheets/d/1q5gdePANXci8enuiS4oHUJxcxC13d6bjMRS...
Chromato asked 1/5, 2020 at 23:1

3

Solved

Here's some silly data that we pivot wider, using two names: library(tidyr) df <- data.frame( food = c('banana','banana','banana','banana','cheese','cheese','cheese','cheese'), binary = c(rep...
Measureless asked 29/9, 2020 at 1:14

3

Solved

I am trying to separate values for the estimates and CIs into three columns, so that the column with info of the type 99.99[-99.9,99.9] is converted into three separated columns. Please consider th...
Heisler asked 27/9, 2022 at 14:29

4

Solved

I would really like pivot_wider to create a column with NAs if the level of a factor exists but never appears in the data when it's used as a names_from argument. For example, the first line gives ...
Cockloft asked 19/11, 2019 at 15:55

1

Solved

I have a nested list from reading a JSON that stores logging info from a video game. The time element of the list is a simple vector, while inputManagerStates and syncedProperties are lists that ma...
Dodona asked 24/8, 2022 at 10:24

6

Solved

Suppose I have some count data that looks like this: library(tidyr) library(dplyr) X.raw <- data.frame( x = as.factor(c("A", "A", "A", "B", "B&quot...
Mame asked 21/9, 2014 at 5:39

© 2022 - 2024 — McMap. All rights reserved.