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

How to include density coloring in pairwise correlation scatter plot

I have the following code: library(GGally) library(nycflights13) library(tidyverse) dat <- nycflights13::flights %>% select(dep_time, sched_dep_time, dep_delay, arr_time, sched_arr_time, arr_delay) %>% …
pdubois
  • 7,640
  • 21
  • 70
  • 99
10
votes
3 answers

Equivalent of apply() by row in the tidyverse?

I want to insert a new column into a data.frame, which value is TRUE when there is at least one missing value in the row and FALSE otherwise. For that problem, apply is a a perfect use case: EDIT - added example tab <- data.frame(a = 1:10, b =…
Kevin Zarca
  • 2,572
  • 1
  • 18
  • 18
10
votes
1 answer

Using modelr::add_predictions for glm

I am trying to calculate the logistic regression prediction for a set of data using the tidyverse and modelr packages. Clearly I am doing something wrong in the add_predictions as I am not receiving the "response" of the logistic function as I would…
Farmer
  • 137
  • 1
  • 8
10
votes
3 answers

R: create dummy variables based on a categorical variable *of lists*

I have a data frame with a categorical variable holding lists of strings, with variable length (it is important because otherwise this question would be a duplicate of this or this), e.g.: df <- data.frame(x = 1:5) df$y <- list("A", c("A", "B"),…
Giora Simchoni
  • 3,487
  • 3
  • 34
  • 72
9
votes
1 answer

Making a diagram map in r?

This is my dataframe: df: Country Total lon lat United Kingdom 5000 -3.43597 55.37805 China 4000 104.1954 35.86166 France 4000 2.213749 46.22764 Australia 4500 …
user19239587
9
votes
0 answers

Any error found in R responds with Error in app$vspace(new_style$`margin-top` %||% 0) : attempt to apply non-function

I honestly don't know how to make this reproducible. Any error that occurs in R, using tidyverse throws: Error in app$vspace(new_style$`margin-top` %||% 0) : attempt to apply non-function Has anybody else seen this? Edit: Here is the…
MRF
  • 377
  • 1
  • 4
  • 15
9
votes
6 answers

Converting grouped tibble to named list

I feel like there is probably a better way to do this in tidyverse than a for-loop. Start with a standard tibble/dataframe, and make a list where the name of the list elements are the unique values of one column (group_by?) and the list elements are…
Jeff Parker
  • 1,809
  • 1
  • 18
  • 28
9
votes
1 answer

Succinctly Reproducing the following graph with R and ggplot2

I borrowed the R code from the link and produced the following graph: Using the same idea, I tried with my data as…
MYaseen208
  • 22,666
  • 37
  • 165
  • 309
9
votes
7 answers

How to summarize the top n values across multiple columns row wise?

In my dataframe, I have multiple columns with student grades. I want to sum the "Quiz" columns (e.g., Quiz1, Quiz2). However, I only want to sum the top 2 values, and ignore the others. I want to create a new column with the total (i.e., the sum of…
AndrewGB
  • 16,126
  • 5
  • 18
  • 49
9
votes
5 answers

Fill missing values with previous values by row using dplyr

I am working with a dataframe in R which has some missing values across rows. Data frame is next (dput added in the end): df id V1 V2 V3 V4 1 01 1 1 1 NA 2 02 2 1 NA NA 3 03 3 1 NA NA 4 04 4 1 2 NA Each row is a different id. As you can…
Duck
  • 39,058
  • 13
  • 42
  • 84
9
votes
6 answers

Accumulate values for every possible combination in R

Let's say I have data test (dput given) where a list-col say items: test <- structure(list(items = list('a', c('b', 'c'), c('d', 'e'), 'f', c('g', 'h')), ID = c(1,1,1,2,2)), row.names = c(NA, 5L), class =…
AnilGoyal
  • 25,297
  • 4
  • 27
  • 45
9
votes
2 answers

Apply function to a row in a data.frame using dplyr

In base R I would do the following: d <- data.frame(a = 1:4, b = 4:1, c = 2:5) apply(d, 1, which.max) With dplyr I could do the following: library(dplyr) d %>% mutate(u = purrr::pmap_int(list(a, b, c), function(...) which.max(c(...)))) If there’s…
thothal
  • 16,690
  • 3
  • 36
  • 71
9
votes
1 answer

Why should I use `all_of` to select columns?

I'm currently using R and came across the function all_of in the tidyverse. What does this function exists for? It seems like I can use just x at every point where all_of(x) can be used.. Example: library(tidyverse) tb <- tibble(a=1:3, b=1:3,…
s1624210
  • 627
  • 4
  • 11
9
votes
3 answers

unnest dataframe within dataframe R

I would like to unnest this dataframe. df <- tibble( bears = c(1,2,3), eagles = tibble( talons = c(2,3,4), beaks = c("x","y","z") ) ) So that it looks like tibble( bears = c(1,2,3), talons = c(2,3,4), beaks =…
Nick
  • 417
  • 4
  • 14
9
votes
3 answers

Using `mutate_at` and `na_if` together to replace zeros with NA for only some columns

My data takes this format: library(tidyverse) df <- mtcars df <- df %>% mutate(vs_doubled = vs * 2) %>% select(mpg, cyl, vs, am, vs_doubled) head(df) #> mpg cyl vs am vs_doubled #> 1 21.0 6 0 1 0 #> 2 21.0 6 0 1 0 #>…
Jeremy K.
  • 1,710
  • 14
  • 35