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
12
votes
3 answers

Printing intermediate results without breaking pipeline in tidyverse

Is there a command to add to tidyverse pipelines that does not break the flow, but produces some side effect, like printing something out. The usecase I have in mind is something like this. In case of a pipeline data %>% mutate(new_var =
Raivo Kolde
  • 729
  • 6
  • 14
12
votes
2 answers

How to filter a data frame programmatically with dplyr and tidy evaluation?

Let's say I want to filter the starwars data frame programmatically. Here's a simple example that lets me filter based on homeworld and species: library(tidyverse) # a function that allows the user to supply filters filter_starwars <-…
tws
  • 697
  • 7
  • 18
12
votes
1 answer

tidyverse interfering with ggplot2? cannot access map_data

Running these commands in the console, the output is: > cty0 = ggplot2::map_data("county") > library(tidyverse) Loading tidyverse: ggplot2 Loading tidyverse: tibble Loading tidyverse: tidyr Loading tidyverse: readr Loading tidyverse: purrr Loading…
Rafael
  • 3,096
  • 1
  • 23
  • 61
11
votes
7 answers

Fitting several regression models by changing only one independent variable within mutate()

I suspect that this question might be a duplicate, however, I found nothing satisfactory. Imagine a simple dataset with a structure like this: set.seed(123) df <- data.frame(cov_a = rbinom(100, 1, prob = 0.5), cov_b = rbinom(100, 1,…
tmfmnk
  • 38,881
  • 4
  • 47
  • 67
11
votes
1 answer

R mutate multiple columns with ifelse

This is a similar problem to this (R Mutate multiple columns with ifelse()-condition), but I have trouble applying it to my problem. Here's a reproducible example: df <- structure(list(comm_id = c("060015", "060015", "060015", "060015", "060015",…
qnp1521
  • 806
  • 6
  • 20
11
votes
2 answers

Is there a pandas equivalent to the tidyr nest function?

The tidyr::unnest method from the R language as an equivalent in pandas and it is called explode as explained in this very detailed answer. I would like to know if there is an equivalent to the ̀tidyr::nest` method. Example R code:…
Paul Rougieux
  • 10,289
  • 4
  • 68
  • 110
11
votes
3 answers

Use broom and tidyverse to run regressions on different dependent variables

I'm looking for a Tidyverse / broom solution that can solve this puzzle: Let's say I have different DVs and a specific set of IVS and I want to perform a regression that considers every DV and this specific set of IVs. I know I can use something…
Luis
  • 1,388
  • 10
  • 30
11
votes
3 answers

Setting row names on a tibble is deprecated. Error: invalid 'row.names' length

I am trying to make a heatmap of a sites vs. species abundances matrix. With thanks to Maurits Evers for some of this code, I am still not able to run it without the error message: Setting row names on a tibble is deprecated.Error in …
chloep
  • 139
  • 1
  • 2
  • 10
11
votes
2 answers

Turn off verbose messages when loading tidyverse using library() function

How does one turn off the many lines of messages when loading tidyverse in R? It doesn't respect the quietly parameter (e.g., library(tidyverse, quietly = TRUE)). Sometimes I might want to see all of the packages it attaches and conflicts, but most…
Rick Donnelly
  • 1,403
  • 3
  • 12
  • 10
11
votes
2 answers

Get the name of a list item created with purrr::map

I retrieved a list of csv files with purrr::map and got a large list. csv_files <- list.files(path = data_path, pattern = '\\.csv$', full.names = TRUE) all_csv <- purrr::map(csv_files, readr::read_csv2) names(all_csv) <- gsub(data_path, "",…
Yann
  • 887
  • 4
  • 12
  • 20
11
votes
3 answers

Applying group_by and summarise(sum) but keep columns with non-relevant conflicting data?

My question is very similar to Applying group_by and summarise on data while keeping all the columns' info but I would like to keep columns which get excluded because they conflict after grouping. Label <-…
mckisa
  • 155
  • 2
  • 2
  • 7
11
votes
6 answers

How do I do a rolling cumsum over consecutive rows of a tibble in R

I have a toy example of a tibble. What is the most efficient way to sum two consecutive rows of y grouped by x library(tibble) l = list(x = c("a", "b", "a", "b", "a", "b"), y = c(1, 4, 3, 3, 7, 0)) df <- as_tibble(l) df #> # A tibble: 6 x 2 #> …
pssguy
  • 3,455
  • 7
  • 38
  • 68
11
votes
2 answers

Error with select function from dplyr

When I use the select function from dplyr, it doesn't work and gives me an error stating that the column names that I want to select are unused arguments. However, if I specify dplyr before the function call like s: "dplyr::select" then it works as…
pd441
  • 2,644
  • 9
  • 30
  • 41
11
votes
3 answers

Table including explicit NAs in R > 3.4.0

EDIT: The accepted answer has helped the scales fall from my eyes; this change is an improvement and not annoying after all. In the help file for table, it is now written: Non-factor arguments a are coerced via factor(a, exclude=exclude). Since R…
Alex Coppock
  • 2,122
  • 3
  • 15
  • 31
10
votes
1 answer

Is there way to pivot_longer to multiple values columns in R?

I'm trying to use pivot_longer to enlongate my dataframe, but I don't need it to be fully long, and would like to output multiple "values" columns. Example: df <- tibble( ids = c("protein1", "protein2"), mean.group1 = sample(1:1000, 2), …
jbandura
  • 127
  • 1
  • 6