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
7
votes
5 answers

Keep common rows among groups based on a column in dplyr

My data frame looks like this df <- data.frame(gene=c("A","B","C","A","B","D"), origin=rep(c("old","new"),each=3), value=sample(rnorm(10,2),6)) gene origin value 1 A old 1.5566908 2 B old…
LDT
  • 2,856
  • 2
  • 15
  • 32
7
votes
1 answer

relevel factors and reorder factors using tidyverse in R

I want to use the functions relevel() and reorder() in my data frame. I understand how relevel works, but I do NOT understand why I do not see the change in the levels in my data.frame. For example, imagine that I have the iris…
LDT
  • 2,856
  • 2
  • 15
  • 32
7
votes
1 answer

R: crosstalk::SharedData linked data with different format (wide/long), when tidyverse verbs don't work

Edit TL;DR Using crosstalk package, I am searching for a way to link a graph that utilizes long format data (a line plot) with an interactive table with data in wide format so that each row in table corresponds to a line in the plot. I am trying to…
Claudiu Papasteri
  • 2,469
  • 1
  • 17
  • 30
7
votes
4 answers

Identifying observations that overlap in space and time

I have a data frame were each row is a unique observation. Observations overlap in time if they are located within a specified temporal distance (e.g. 30 days) of one another. Observations overlap in space if they are located within a specified…
rjen
  • 1,938
  • 1
  • 7
  • 19
7
votes
1 answer

What is the "embracing operator" `{{ }}`?

I just came across the "embracing operator" {{ }} in section 2.2.3 of the tidyverse style guide. What does the embracing operator {{ }} do in R?
sieste
  • 8,296
  • 3
  • 33
  • 48
7
votes
2 answers

Is there a way to embed a ggplot image dynamically by row (like a sparkline) using the gt package?

I'm trying to replicate this process and get the gt package to render ggplot objects where each row in the table gets a different graph (like a spark line). There appears to be a solution on the linked page, but when I try to replicate it, I get the…
7
votes
1 answer

Replace values in tibble in R 4.0

I just upgraded to R 4.0.0 from R 3.6.2 and some functionality that I use to replace values in a tibble no longer works. I can't find what I need to do now. Does anyone know the "new" way? library(tidyverse) v <- c(1, 2, 3) w <- c(4, 4) i <- 1 #…
zouth0
  • 83
  • 1
  • 6
7
votes
2 answers

Interpolation of irregular time series with R

Searching for linear interpolation of time series data in R, I often found recommendations to use na.approx() from the zoo package. However, with irregular timeseries I experienced problems, because interpolated values are distributed evenly across…
7
votes
1 answer

How to change font size for all text in a ggplot object relative to current value?

When creating plots using ggplot2, I often encounter the following: I have twitched all the text using element_text(size=), so it looks good in my report, but to use it in another context, I need to update the size of all text (make it…
Benjamin Schwetz
  • 624
  • 5
  • 17
7
votes
3 answers

Creating one variable from a list of variables in R?

I have a sequence of variables in a dataframe (over 100) and I would like to create an indicator variable for if particular text patterns are present in any of the variables. Below is an example with three variables. One solution I've found is using…
7
votes
2 answers

How to speed up iteration while working on a data-frame with over 5 million observations in r?

I am trying to generate values for over 7 variables across millions of observations and it's taking forever when I write a for loop to achieve this. Below is an example of what I am trying to achieve. In this case it's fast since it has only a few…
Dal
  • 317
  • 1
  • 8
7
votes
1 answer

Can't use !!arg in dplyr for mutate call

I can use !! to filter by a user-given variable but not to modify that same variable. The following function throws an error when created, but it works just fine if I delete the mutate call. avg_dims <- function(x, y) { y <- enquo(y) x %>% …
overdisperse
  • 416
  • 3
  • 13
7
votes
1 answer

Connecting to Microsoft SQL Server with R (view is in a database in Microsoft SQL Server Management Studio (SSMS)

I have reading rights to some "Views" (tables) in Microsoft SQL Server Management Studio (SSMS). I connect, make my query and export a files as csv and then read it in R. Now I would like to make my queries inside R. I have spendt some hours…
xhr489
  • 1,957
  • 13
  • 39
7
votes
3 answers

Stack a named Date list to data.frame

I am doing a school project of data cleaning with tidyverse package. Now I get a list output from purrr::map() like this: (mylist <- list(A = as.Date(sample(1e3:1e4, 4), origin = "1960-01-01"), B = as.Date(sample(1e3:1e4, 2), origin…
Darren Tsai
  • 32,117
  • 5
  • 21
  • 51
7
votes
2 answers

Unnest list and gather items with purrr

I have a list like: list(list(goals = c(42L, 52L, 55L), season = "88", player = c("a", "b","c")), list(goals = c(41L,53L, 37L, 40L), season = "89", player = c("a","b", "c", "d"))) I want to convert…
Domino55
  • 73
  • 3