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
2
votes
0 answers

Split large dataframe into smaller dataframes based on file size

I have a large dataframe containing multiple variables (categorical and numerical), which I want to split into smaller ones such that each smaller file that I export (as CSV) is not larger than 1 MB. I would also like to do this in the tidy style,…
2
votes
2 answers

pivot wider while keeping the order

I have the following dataset order_id <- c(2,2,2,3,3,3) product_name <- c("banana","Garlic Powder","carrots","milk","banana","Coconut Butter") (df <- data.frame(order_id,product_name)) order_id product_name 1 2 banana 2 …
Nathan123
  • 763
  • 5
  • 18
2
votes
1 answer

How to mutate and map conditional on values of grouping variables?

Assume the following example workflow. Such code will allow to map a function over grouped variables df <- tibble(group1 = rep(letters[1:10],100), group2 = rep(letters[1:10],100), var1 = rnorm(1000), var2 =…
Raed Hamed
  • 327
  • 1
  • 10
2
votes
2 answers

collapse R package: rearraning or reposition columns in custom order

I'm using collapse R package want to reposition columns. In tidyverse or dplyr, this can be achieved by using everything() function. However everything() function is not working with fselect function from collapse. Any…
MYaseen208
  • 22,666
  • 37
  • 165
  • 309
2
votes
2 answers

Way to avoid nested ifelse statement in R

I have a dataframe that includes various ages and a value for each age. I would like to classify the different ages into broader age groups. To do so, I had to create a fairly complicated nested ifelse statement: library(tidyverse) df <-…
user3710004
  • 511
  • 1
  • 6
  • 15
2
votes
1 answer

Summary of all numeric variables with collapse R package

The summary of multiple variables may be obtained by applying fsummarise and across functions from collapse R package. For example: library(collapse) library(magrittr) wlddev %>% fgroup_by(region, income) %>% fsummarise(across(PCGDP:GINI,…
MYaseen208
  • 22,666
  • 37
  • 165
  • 309
2
votes
2 answers

Use map with nested lists

I am struggling with using map from the library purrr correctly. I would like to calculate the weighted mean of my sample by nesting a common observations in a list and then using map(). (I know this would also work with group_by) MWE: Suppose I…
Methamortix
  • 70
  • 10
2
votes
2 answers

R - Issues with group order/ ggplot dodge barchart

I looked through other questions but I didn't find this exact problem company<-c("c1","c1","c2","c2","c2","c3","c3","c3","c4","c4", "c4") subsegment<- c("Sub2","Sub3", "Sub1","Sub2", "Sub3", "Sub1","Sub2", "Sub3", "Sub1","Sub2",…
lu-202
  • 121
  • 7
2
votes
1 answer

How to make a line graph in ggplot with discrete x-axis?

So I have a table as follows: data <- structure(list(Variable = c("Content", "Content", "Content", "Content", "Content", "Content"), content_type = c("LIVE", "LIVE", "LIVE", "VOD", "VOD", "VOD"), CURRENT_STATUS = c("ACTIVE", "CANCELLED",…
John Thomas
  • 1,075
  • 9
  • 32
2
votes
3 answers

Counting observations by group using collapse R package

I want to translate the following R code from tidyverse to collapse. The following code count observations by group and append as a column to the data.frame. library(tidyverse) library(collapse) head(wlddev) wlddev %>% group_by(income) %>% …
MYaseen208
  • 22,666
  • 37
  • 165
  • 309
2
votes
5 answers

Finding combined sums of pairs of rows in R

I have a dataframe with test results (rows being Players; and columns Q1 ... Q6 being the different questions). Now I want to find out which pair of players scored the highest sum in total: # Generating sample data. n = 6 set.seed(1986) results_df…
Methi
  • 43
  • 4
2
votes
2 answers

How to split bigrams into column and row pairs for n-columns

Supposing a dataframe like this: # example dataset df <- data.frame( rowid = 1:3, a = c("ax","cz","by"), b = c("cy","ax","bz"), c = c("bz","ay","cx") ) What would an efficient approach be to achieving the…
louisdesu
  • 55
  • 6
2
votes
0 answers

R package build check warning about "scales"

I am building an R package, and I am constantly getting this warning about "scales" (below). I scanned my entire code, but I can't figure out where the problem is. Any suggestions would be helpful. Thanks! > checking dependencies in R code ...…
Rohit Farmer
  • 319
  • 4
  • 15
2
votes
1 answer

Define decimal separator with vroom

I often face csv files, which were saved with a German locale and are therefore not properly comma-separated, but rather are separated with a semi-colon. This is of course easily solvable by defining the separator. But vroom in contrast to for…
hannes101
  • 2,410
  • 1
  • 17
  • 40
2
votes
0 answers

Data formatting issues; Is my function the problem?

every day I get an email listing sales in a shop for the previous day. My email looks like this: Date of report:,15-JAN-2022 Time report produced:,16-JAN-2022 00:25 Service:…
alec22
  • 735
  • 2
  • 12