Questions tagged [tidyverse]

ONLY use this tag if your question relates to the installation, integration with your system, or inclusion of the entire tidyverse library. DO NOT USE if your question relates to one or two components of the tidyverse, such as dplyr or ggplot2. Use *those* tags, and tag with `r` as well for a better response.

tidyverse is an R package that installs a number of other packages for data processing and graphics.

Unless your question is about the entirety of the tidyverse package, its installation or its integration with your system, use tags for the packages you are actually using. Using library(tidyverse) is rarely a minimal reproducible example when only library(dplyr) is required.

See https://www.tidyverse.org/packages/ for a breakdown of the packages contained in tidyverse and their respective functions.

Repositories

Resources

Vignettes

Related tags

9739 questions
6
votes
2 answers

How can I use a progress bar for piped functions in R / tidyverse

I have a main function which performs a handful of variously complicated (and long-running) computations on some data, it performs these steps using the pipe from tidyverse / magrittr. I would like a progress bar to report on the stage of the…
Moohan
  • 933
  • 1
  • 9
  • 27
6
votes
5 answers

Count number of rows where a value appears in any of two columns in R

I have a dataset like this: data <- read.csv(text = "foo,bar a,b a,a b,c c,a c,b") I want to compute a table that tells me in how many rows every possible value appears, so something like this: Value Count a 3 b 3 c 3 I've tried…
jjmerelo
  • 22,578
  • 8
  • 40
  • 86
6
votes
4 answers

How to apply t-test between ranges of columns in R

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 each row (human_A,human_B,human_C) vs…
LDT
  • 2,856
  • 2
  • 15
  • 32
6
votes
2 answers

How to fill in the missing values in a dataframe in R, where the logic for filling in missing values is percentage change estimation?

I am working with cost data for a retailer, where I am making some predictions using gam that look as follows (sample data, self-generated). The GAM fits values in the middle, but has some NAs at the extremes. The elasticity is calculated as a…
Sarthak Nigam
  • 117
  • 1
  • 10
6
votes
6 answers

Using a vector of new and old names in tidyverse to select and rename columns

I want to select columns and rename them based on the names of the columns which I keep in a separate dataframe. This is the original dataset: df <- tribble( ~year, ~country, ~series1, ~series2, 2003, "USA", 8, 5, 2004, "USA", 9, 6, 2005,…
ulima2_
  • 1,276
  • 1
  • 13
  • 23
6
votes
2 answers

`magrittr` pipe into apply

How do you pipe an object into a specific place in an apply call, that isn't the first input? The magrittr dot placeholder does not seem to work for this. dat <- 1:10 locs <- list(c(1, 2), c(3, 4), c(5, 6)) …
hokeybot
  • 195
  • 5
6
votes
4 answers

Extracting specific variable names into a single variable

I would to pick out any variable with ## in each row then store such variables in the vars_extract variable. Any idea? library(tidyverse) df <- tibble( "a1" = c("##", 3, NA, 4, 5), "a2" = c(10, 38, "##", 4, 5), "a3" = c(11, 34, NA, 4, 5), …
Moses
  • 1,391
  • 10
  • 25
6
votes
1 answer

pivot_longer with a very big data.frame, memory efficient approaches

I have a data.frame of hospital data with 11 million rows. Columns: ID (chr), outcome (1|0), 20x ICD-10 codes (chr). Rows: 10.6 million I wish to make the data tidy to allow modelling of diagnostic codes to a binary outcome. I would normally use…
JisL
  • 161
  • 8
6
votes
6 answers

How to detect range of positions of specific set of characters in a string

I have the following sequence: my_seq <- "----?????-----?V?D????-------???IL??A?---" What I want to do is to detect range of positions of non-dashed characters. ----?????-----?V?D????-------???IL??A?--- | | | | | | | 1 …
littleworth
  • 4,781
  • 6
  • 42
  • 76
6
votes
5 answers

do() superseded! Alternative is to use across(), nest_by(), and summarise, how?

I'm doing something quite simple. Given a dataframe of start dates and end dates for specific periods I want to expand/create a full sequence for each period binned by week (with the factor for each row), then output this in a single large…
Dasr
  • 777
  • 6
  • 16
6
votes
3 answers

Two equivalent commands give different returns in r

Why do the following two commands not return the same output? x <- sample(0:1, 50, replace = TRUE, prob = c(0.5, 0.5)) sum(x==1) sample(0:1, 50, replace = TRUE, prob = c(0.5, 0.5)) %>% sum(.==1) The first of the 2 command always gives me the…
Dave Twickenham
  • 171
  • 1
  • 8
6
votes
1 answer

facet grid using .data pronoun on both formula sides not working

I am trying designing an interactive plot. I want the user to specify the facet_grid formula, however if in both sides of the formula .data pronoun it does not work. Any workaround? left <- 'Species' right <- 'Petal.Width' ### not working…
Kozolovska
  • 1,090
  • 6
  • 14
6
votes
3 answers

alternatives to eval parse with dplyr

Is there a way to do filter with a string as parameter without using eval(parse())? library("dplyr") subset <- "carb == 4" subset_df <- mtcars %>% filter(eval(parse(text = subset)))
hxalchemy
  • 366
  • 1
  • 10
6
votes
3 answers

Combining time trend plot with timeline

I want to create a plot (preferable using ggplot2) where I visualize a timeline together with a time-trend plot. To put it in a practical example, I have aggregated unemployment rates for each year. I also have a data set denoting important…
ecl
  • 369
  • 1
  • 15
6
votes
1 answer

R ERROR: dependencies ‘xml2’, ‘httr’ are not available for package (Linux Mint 20.1)

I did not quite know where this belongs exactly, so I decided to post this here on stack overflow. I recently had package issues with R and R-Studio on Linux Mint 20.1, where I always recieved dependency errors when installing packages like plotly…
Tbroeth
  • 345
  • 2
  • 12