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

Iterating over multiple regression models and data subsets in R

I am trying to learn how to automate running 3 or more regression models over subsets of a dataset using the purrr and broom packages in R. I am doing this with the nest %>% mutate(map()) %>% unnest() flow in mind. I am able to replicate examples…
user11151932
  • 223
  • 1
  • 5
6
votes
1 answer

using `rlang` NSE to group by multiple variables

I am trying to write a custom function that uses rlang's non-standard evaluation to group a dataframe by more than one variable. This is what I've- library(rlang) # function definition tryfn <- function(data, groups, ...) { # preparing data df…
Indrajeet Patil
  • 4,673
  • 2
  • 20
  • 51
6
votes
3 answers

From list to data frame with tidyverse, selecting specific list elements

A simple question but I've searched for a solution, and so far to no avail. Say that I have a list object, and I want to pull specific list elements and output them side-by-side as dataframe columns. How can I achieve this with tidyverse/piping in a…
Emman
  • 3,695
  • 2
  • 20
  • 44
6
votes
4 answers

Split a list into separate data frame in R

So I have a list with me as below, what I want is to split them into three separate dataframes (with names as Banana/Strawberry & apple) as shown in expected output. I have already seen this (Splitting List into dataframe R) but its exact opposite…
Vaibhav Singh
  • 1,159
  • 1
  • 10
  • 25
6
votes
10 answers

Separate a shopping list into multiple columns

I have a shopping list data like this: df <- data.frame(id = 1:5, item = c("apple2milk5", "milk1", "juice3apple5", "egg10juice1", "egg8milk2"), stringsAsFactors = F) # id item # 1 1 apple2milk5 # 2 2 milk1 # 3 3 juice3apple5 #…
Darren Tsai
  • 32,117
  • 5
  • 21
  • 51
6
votes
1 answer

Use function arguments in purrr::possibly otherwise

Is there a way to use the arguments passed to the original function in the otherwise argument of purrr::possibly()? For example (this is a dumb toy example--the real code involves web scraping behind a password-protected…
crazybilly
  • 2,992
  • 1
  • 16
  • 42
6
votes
2 answers

Pivot wider produces nested object

This is regarding latest tidyr release. I am trying pivot_wider & pivot_longer function from library(tidyr) (Update 1.0.0) I was trying to obtain normal iris dataset when I run below but instead I get nested sort of 3X5 dimension tibble, not sure…
user12059497
6
votes
4 answers

Generating dynamic variables referencing existing variables

I'm trying to generate a correlation matrix with significance stars. Take the following dataframe: df <- tibble(stub = c(1,2,3,4), stub_pvalue = c(.00, .04, .07,.2)) I'd like to write a function that pastes any column (e.g. stub in…
6
votes
2 answers

How to construct arguments for case_when from data frame?

I'm trying to create many different possible weighting schemes based on temperature. I created a data frame with all possible combinations of 8 vectors (each vector represents a temperature range). So the columns of the data frame are a specific…
Giovanni Colitti
  • 1,982
  • 11
  • 24
6
votes
3 answers

Turning a data frame and a list into long format with dplyr

Here is a puzzle. Assume you have a data frame and a list. The list has as many elements as the df has rows: dd <- data.frame(ID=1:3, Name=LETTERS[1:3]) dl <- map(4:6, rnorm) %>% set_names(letters[1:3]) Is there a simple way (preferably with dplyr…
January
  • 16,320
  • 6
  • 52
  • 74
6
votes
2 answers

Error casted by simple mutate using tidyverse or dplyr

I am having serious troubles using the tidyverse package that I cannot debug. As an example, "mutate" does not work properly even on past project I have already produced. This all started when I installed the following…
fbm81
  • 61
  • 1
  • 4
6
votes
2 answers

Summarize data within multiple groups of a time series

I have a series of observations of birds at different locations and times. The data frame looks like this: birdID site ts 1 A 2013-04-15 09:29 1 A 2013-04-19 01:22 1 A 2013-04-20 23:13 1 …
sbliss
  • 87
  • 2
6
votes
5 answers

Splitting strings into number and string (with missings)

I am trying to separate numbers and characters in a column of strings. So far I have been using tidyr::separate for doing this, but am encountering errors for "unusual" cases. Suppose I have the following data df <- data.frame(c1 = c("5.5K", "2M",…
user11151932
  • 223
  • 1
  • 5
6
votes
1 answer

How to use rlang operators in a package?

I am writing a package that uses tidyverse functions, i.e. that use non-standard evaluation, like dplyr::filter for example: setMethod("filter_by_id", signature(x = "studies", id = "character"), definition = function(x, id) { …
Ramiro Magno
  • 3,085
  • 15
  • 30
6
votes
3 answers

R: Using pipe %>% and pkg::fo leads to error "Error in .::base : unused argument"

I am using magrittr's pipe %>%, followed immediately by a function called by: package::function, and get the error: Error in .::base : unused argument (mean) What is the problem? library(magrittr) c(1,2) %>% base::mean #> Error in .::base: unused…
Matifou
  • 7,968
  • 3
  • 47
  • 52