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

String based filtering in dplyr - NSE

I'd like to use dplyr's new NSE notations (version >= 0.6) for a dynamic filter on my data. Let's say I have the following dummy dataset: df = data_frame(x = 1:10, y = 10:1, z = 10 * runif(10)) If now I want to filter column tofilter = "x" for…
Lorenzo Rossi
  • 1,481
  • 1
  • 9
  • 16
7
votes
2 answers

Create a unique legend based on a contingency (2x2) table in geom_map or ggplot2?

How can I do this based on this contingency table? I'm not entirely sure how to create a custom legend in R based on the indicator table I made (crimes). Reproducible code in R: require(maps) set.seed(123) # randomly assign 2 variables…
skhan8
  • 121
  • 4
7
votes
1 answer

Tidy evaluation when column names are stored in strings

I need to filter a table by a logical column (or, more precisely, by its negation), but the name of the column may vary. It's easy when I know their names beforehand: tb = tibble( id = 1:4, col1 = c(TRUE, TRUE, FALSE, FALSE), col2 = c(TRUE,…
Luiz Rodrigo
  • 936
  • 1
  • 7
  • 19
7
votes
1 answer

replace NA with 0 using starts_with()

I am trying to replace NA values for a specific set of columns in my tibble. The columns all start with the same prefix so I am wanting to know if there is a concise way to make use of the starts_with() function from the dplyr package that would…
Dan
  • 2,625
  • 5
  • 27
  • 42
7
votes
2 answers

How to replace string for every row in specfic column using dplyr and stringr

I have the following tibble: library(tidyverse) df <- tibble::tribble( ~sample, ~colB, ~colC, "foo", 1, 2, "bar_x", 2, 3, "qux.6hr.ID", 3, 4, "dog", 1, 1 ) df #> # A tibble: 4 x 3 #> sample colB colC #> …
pdubois
  • 7,640
  • 21
  • 70
  • 99
7
votes
2 answers

Convert data frame row to column names

Is there a quick way (part of the tidyverse API perhaps) to turn a row into column names for a data.frame or tibble, somewhat similar to tibble::column_to_rownames? I realize there are many ways to do this, e.g. somewhat clumsily: > df <-…
saladi
  • 3,103
  • 6
  • 36
  • 61
7
votes
4 answers

How to detect if bare variable or string

I am trying to write a plotting function where you can pass bare column names to select which columns are plotted. I would like also to be able to specify a string as the color. I have found that I need to use shQuote if I want to pass a string to…
Jan Stanstrup
  • 1,152
  • 11
  • 28
7
votes
2 answers

How to import ical .ics file in R

I would like to import a .ics file into R, however, when I try to do so like... sneak_cal <- read.delim("iCal-TribeEvents.ics", sep = ":", header=FALSE, stringsAsFactors = FALSE, strip.white = TRUE, na.strings = "") ...I end up splitting the…
Scott
  • 642
  • 7
  • 16
7
votes
4 answers

R - ggplot2 'dodge' geom_step() to overlap geom_bar()

Plotting counts using ggplot2's geom_bar(stat="identity") is an effective method of visualising counts. I would like to use this method to display my observed counts and compare them to expected counts I would like to do this by using geom_step to…
G_T
  • 1,555
  • 1
  • 18
  • 34
7
votes
1 answer

tidyverse: count number of a specific level when summarizing

I would like, when summarizing after grouping, to count the number of a specific level of another factor. In the working example below, I would like to count the number of "male" levels in each group. I've tried many things with count, tally and so…
Dominique Makowski
  • 1,511
  • 1
  • 13
  • 30
7
votes
0 answers

Can we access all data columns in a custom ggplot2's stat?

I would like to implement diagnostics for Cox proportional hazards model with ggplot2, by creating new stats functions and ggproto objects. The idea is to benefit from grouping (by color, facet_grid, etc.) for conditional computation of desired…
mjktfw
  • 840
  • 6
  • 14
7
votes
2 answers

package ‘tidyverse’ is not available

I am trying to install "tidyverse" and I get the below error. install.packages("tidyverse") package ‘tidyverse’ is available as a source package but not as a binary Warning in install.packages : package ‘tidyverse’ is not available (as a binary…
poppy202
  • 85
  • 1
  • 1
  • 5
7
votes
1 answer

Generate a sequence of time using R and lubridate

Is there an efficient way to generate a time-sequence vector with tidyverse and lubridate? I know the two can work with seq() when one use the number of dates as the interval. For example, with the input: seq(today(), today()+dyears(1), 60) one can…
Carl H
  • 1,036
  • 2
  • 15
  • 27
7
votes
5 answers

Simulating a timeseries in dplyr instead of using a for loop

So, while lag and lead in dplyr are great, I want to simulate a timeseries of something like population growth. My old school code would look something like: tdf <- data.frame(time=1:5, pop=50) for(i in 2:5){ tdf$pop[i] =…
jebyrnes
  • 9,082
  • 5
  • 30
  • 33
6
votes
1 answer

Print message in the middle of long pipe

In my R script, I would like to print a message in the middle of a long pipe (which takes a long time to run) without breaking the pipe. I need this to track the progress of the running pipeline. I tried to create a simple function that prints a…
Ahmed El-Gabbas
  • 398
  • 3
  • 10