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
1 answer

Why doesn't `pivot_wider` work on a `data.table`

A simple example of long to wide pivot: library(tidyverse) library(data.table) df <- data.frame(names=letters[1:3],values=1:3) df %>% pivot_wider(names_from=names,values_from=values) #works dt <- data.table(names=letters[1:3],values=1:3) dt %>%…
LucasMation
  • 2,408
  • 2
  • 22
  • 45
6
votes
3 answers

R dplyr: how to use ... with summarize(across()) when ... will refer to a variable name within the data?

I want to have a flexible function using summarize in which: the aggregation function is given by user the aggregation function might use further arguments which refer to variables within the data itself. A good example is the user providing…
Matifou
  • 7,968
  • 3
  • 47
  • 52
6
votes
2 answers

Eliminate the ungroup... message from tidyverse package

When I run the following command I get an annoying message that says: summarise() ungrouping output (override with .groups argument). I was wondering how I can eliminate this message in my data below? library(tidyverse) hsb <-…
rnorouzian
  • 7,397
  • 5
  • 27
  • 72
6
votes
1 answer

Tidyr: pivot_wider error: Can't convert to

I have a dataframe which lists species observations across multiple survey plots (the data is here). I'm trying to use tidyr's pivot_wider to spread that abundance data across several columns, with the new columns being each of the observed…
Kronimiciad
  • 190
  • 1
  • 2
  • 11
6
votes
1 answer

Transposition of a Tibble Using Pivot_Longer() and Pivot_Wider (Tidyverse)

The similar questions on this topic all used spread() and gather() which are retired Tidyverse functions. Let's say I have a tibble as such: people 1 2 3. 4 5 person1 27000 30000 40000 50000 60000 person2 27000 30000 40000 50000…
Steveman30290
  • 511
  • 7
  • 17
6
votes
1 answer

How to exact match two column values in entire Dataset using R

I have below-mentioned two dataframe in R, and I have tried various method but couldn't achieve the required output yet. DF: ID Date city code uid I-1 2020-01-01 10:12:15 New York 123 K-1 I-1 2020-01-01…
Sophia Wilson
  • 581
  • 3
  • 16
6
votes
2 answers

Replacing group_by_at(NULL) using across

Before, I used group_by_at to group by a vector of strings or by NULL: library(tidyverse) grouping_1 <- c("cyl", "vs") grouping_2 <- NULL mtcars %>% group_by_at(grouping_1) mtcars %>% group_by_at(grouping_2) The help of group_by_at indicates…
danilinares
  • 1,172
  • 1
  • 9
  • 28
6
votes
2 answers

Pivoting data with varying width from wide to long with flexible call (to be used in loop)

I need to pivot some wide time-series data, that is varying width regard to width using tidyr's pivot_longer(). The data is quarterly, but I receive the data in both years-blocks (with with four quarters) and in six months blocks (with only two…
Eric Fail
  • 8,191
  • 8
  • 72
  • 128
6
votes
3 answers

Pipe/dplyr friendly way to filter non zero elements of a vector

Surprisingly I am not finding an answer to this easy question. I need a pipe-friendly way to count the number of non-zero elements in a vector. Without piping: v <- c(1.1,2.2,0,0) length(which(v != 0)) When I try to do this with pipes I get an…
LucasMation
  • 2,408
  • 2
  • 22
  • 45
6
votes
1 answer

R dplyr - Rearrange columns by pattern of names

I've got some long format data that 1) needs to be reshaped to wide and then 2) needs the columns resorted according pattern of their names. The example data is below: #Orignial data set.seed(100) long_df <- tibble(id = rep(1:5, each = 3), …
Paryl
  • 201
  • 2
  • 11
6
votes
1 answer

Generate a comprehensive report format in R

I have fetched some information form the MySQL server into R which looks like as follows in my R dataframe: barcode_no Inspection_date current_profile score Tag_log prod_log 12345678 2020-01-15 14:34:13 Large …
Mike
  • 61
  • 3
6
votes
1 answer

Emi calculation for the grace month in R

From my previous question, I have tried to simplify the calculation. I kept the following variables to my dataframe. dataframe1: This is the normal scenarios. uid emi_date amt interest tenure emi Rep_seq status balance KII-453…
Sophia Wilson
  • 581
  • 3
  • 16
6
votes
2 answers

Conditionally determining value of column by looking at last group

I have test data that looks like this: Group Value 1 a 1 2 a 2 3 a 3 4 a 4 5 b 5 6 b 2 7 b 3 8 c 6 9 c 7 10 c 8 11 c 3 12 c 6 13 d …
sumshyftw
  • 1,111
  • 6
  • 14
6
votes
1 answer

Emulating reshape2::melt with pivot_longer for matrixes

i just tried to use pivot_longer on a 2D Matrix to get "tidy" data for ggplot. So far that was pretty straight forward with reshape2::melt library(tidyverse) library(reshape2) x <- c(1, 2, 3, 4) y <- c(1, 2, 3) Data <- matrix(round(rnorm(12,…
SebSta
  • 476
  • 2
  • 12
6
votes
1 answer

Is there any explicit guarantee that dplyr operations preserve row order?

When I teach people how to use dplyr, I warn them not to assume that any dplyr functions will preserve the order of their dataframes/tibbles unless otherwise stated by documentation. However, I have not been able to find any official documentation…
anjama
  • 400
  • 2
  • 9