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

Include vertical line in ggplot based on value in other column in ggplot

That's a confusing title but what I have is a df (much larger, but) like this: df # A tibble: 10 × 3 week count protest 1 1 259. 0 2 2 509. 0 3 3 556. 0 4 4 588. 0 5 5 …
AntVal
  • 583
  • 3
  • 18
2
votes
0 answers

How to read very small scientific number with readr

I have the following file with tab separator: Motif Name P-value Fra1 1e-613 Atf3 1e-585 Fra2 1e-576 JunB 1e-559 BATF 1e-550 AP-1 1e-537 Fosl2 1e-513 Jun-AP1 1e-473 Bach2 1e-193 When I try to read it with this code: infile <-…
littleworth
  • 4,781
  • 6
  • 42
  • 76
2
votes
2 answers

Reshape data according to column name pattern

df <- structure(list(`1.tes1` = 8.00073085700465, `1.tes2` = 8.08008192865136, `1.tes3` = 7.67643993710322, `1.tes4` = 4.40797764861845, `1.tes5` = 8.07887886210789, `1.tes6` = 7.5133416960745, `2.tes1` = 8.85382519278079, `2.tes2` =…
Tianjian Qin
  • 525
  • 4
  • 14
2
votes
1 answer

The title of my discrete y axis won't move in ggplot2

I've got the following data: library(ggplot2) library(magrittr) library(tidyverse) library(scales) mydata <- structure(list(group = c("All participants", "Subgroup 1", "Subgroup 2", "Subgroup 3"), group_factor = structure(4:1,…
tcvdb1992
  • 413
  • 3
  • 12
2
votes
1 answer

Detect type of string and create new variable accordingly to it

So i have a dataset of passwords and i would like to create a new column if the password matches one of the following strings (im working with R) id password year lenght 1 1 12345 2001 5 2 2 pass4 2002 5 3 3 angel …
Em Manuel
  • 93
  • 6
2
votes
2 answers

Is there a efficient way to mutate only on rows that meet a condition? Think mutate(when(condition))

I am looking to apply a mutate only when certain conditions are met. I know I can do this... data2 <- data1 %>% group_by(a, b) %>% mutate( var1 = case_when( condition ~ TRUE, TRUE ~ FALSE, NA ), …
k6adams
  • 406
  • 1
  • 3
  • 12
2
votes
2 answers

mutate(across) to generate multiple new columns in tidyverse

I usually have to perform equivalent calculations on a series of variables/columns that can be identified by their suffix (ranging, let's say from _a to _i) and save the result in new variables/columns. The calculations are equivalent, but vary…
2
votes
2 answers

Performing arithmetic across data frames (tibbles)

Is there a way to multiply each variable (a, b, c) value in df by its corresponding group mean and divide by its standard deviation in df_summary. I would like to do it without hardcoding? Thanks library(tidyverse) set.seed(1) df <- tibble(a =…
sparklink
  • 41
  • 2
2
votes
3 answers

Extracting a date from a column and adding the year if missing in R

I am trying to extract dates from text and create a new column in a dataset. Dates are entered in different formats in column A1 (either mm-dd-yy or mm-dd). I need to find a way to identify the date in column A1 and then add the year if it is…
Michael Matta
  • 394
  • 2
  • 16
2
votes
1 answer

How to use geom_bar and use two categorical variables on the x axis

I try to do a bar plot, with an X axis a bit different than usual. The idea is to represent this axis by the initial variable (code) and by a grouping variable (region). Each code has one region attributed to it. And I would like vertical line to…
2
votes
3 answers

Apply a function to each combination of two lists elements

I want to apply a function to each combination of two lists elements. library(tidyverse) map( .x = c(0, 1) , .f = function(x) { qnorm(p = 0.05, mean = x, sd = 1, lower.tail = FALSE) } ) [[1]] [1] 1.644854 [[2]] [1] 2.644854 map( …
MYaseen208
  • 22,666
  • 37
  • 165
  • 309
2
votes
1 answer

Conversion of data type in R does not seem to work as expected

I could really use some help here with my RStudio. I am trying out this analysis and seem to have problem converting data type of certain variables. library(tidyverse) library(lubridate) library(ggplot2) library(magrittr) Nov2020 <-…
Jiawei
  • 23
  • 2
2
votes
2 answers

Complete column names with another dataframe column in R

I have this table: library(rvest) library(tidyverse) tables_team_pl <- read_html('https://www.win-or-lose.com/football-team-colours/') color_table <- tables_team_pl %>% html_table() %>% pluck(1) %>% select(-Away) and also this one: table_1 <-…
Laura
  • 675
  • 10
  • 32
2
votes
1 answer

Pairwise Difference Between Pairs of Observations within an R data frame

I have a two data frames. One data frame identifies pairs of observations where pairs are unique but an element can be part of more than one pair (See below). PairID PairElement1 PairElement2 1 A B 2 C …
user49017
  • 137
  • 1
  • 6
2
votes
4 answers

Finding a list of previous max values in order of a vector R

I want to find a list of previous max. So for a vector: 3, 2,2,3,4,3,9,5,2,3,4,6,120,1 The first max is 3, the second max is 4 (because, 4>3), then 9(because 9>4) and then 120 (120>9) So, as an output I would need the position: 1,5,7,13 Is there…
1 2 3
99
100