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

Break a small sentence in multiple rows with a single string each in R dplyr

I have a data frame that looks like this library(tidyverse) data=data.frame(POS=c(172367,10), SNP=c("ATCG","AG"), QUAL=c(30,20)) data #> POS SNP QUAL #> 1 172367 ATCG 30 #> 2 10 AG 20 Created on 2022-02-02 by the reprex package…
LDT
  • 2,856
  • 2
  • 15
  • 32
2
votes
1 answer

Construct JSON column from R dataframe columns

Here is my dataframe: df <- data.frame(item = c("Box 1", "Tape", "Roll 1"), Length = c(2, 10, 6), Width = c(4,3,3), Height = c(6, NA, NA), Length_units = c("in", "ft", "yd"), option_1 = c("item_length", "item_length", "item_length"), option_2 =…
Chris
  • 125
  • 7
2
votes
2 answers

Count the number of observations across multiple columns and create new categories

I have data like these: ID color_1 color_2 color_3 color_4 1 blue NA NA NA 5 green blue yellow NA 9 None NA NA NA 2 blue pink NA NA…
alex
  • 858
  • 5
  • 14
2
votes
2 answers

Read in CSV files and Add a Column with File name

Assume you have 2 files as follows. file_1_october.csv file_2_november.csv The files have identical columns. So I want to read both files in R which I can easily do with map. I also want to include in each read file a column month with the name of…
John Karuitha
  • 331
  • 3
  • 11
2
votes
1 answer

R tidysynth, problem with generate_control

I keep encountering a problem while running tidysynth. I'm pretty new to R and I'm applying the tidysynth manual to my data. I keep getting the message "Error in unique(data$.id) : argument "data" is missing, with no default" after the…
Yongjin
  • 31
  • 1
2
votes
2 answers

Unlist a list from cells into seperate columns - Error

I've used the function acf to AutoCorrelate by group: group_by(filterindex) %>% summarise(ac = list(acf(meanValence, lag.max = 10))) My result is a DF with 2 column (filterindex and ac) and has 10 rows. The secound column, "ac" contains in each…
Ido
  • 201
  • 1
  • 8
2
votes
1 answer

Extract strings using fuzzy LR patterns in R

I am struggling for long time. I manage to extract everything between my Right and Left patterns in a string as you can see in the following example. library(tidyverse) data=c("everything will be ok one day") str_extract(string = data, pattern =…
LDT
  • 2,856
  • 2
  • 15
  • 32
2
votes
1 answer

Animation time with gganimate

I want to make a plot animate. I need that the points appear and disappear, but only make that the movements of points. set.seed(1) library(tidyverse) library(gganimate) df <- tibble( x = rnorm(100) , y = rnorm(100) , size = rep(c(2, 3, 4, 5),…
2
votes
1 answer

Unexpected dplyr::bind_rows() behavior

Short Version: I'm encountering an error with dplyr::bind_rows() which I don't understand. I want to split my data based on some condition (e.g. a == 1), operate on one part (e.g. b = b * 10), and bind it back to the other part using…
Dan Adams
  • 4,971
  • 9
  • 28
2
votes
1 answer

Unable to import text column data contained in separate lines

I have raw data in this txt format: Name|Occupation|Comment Robert|Doctor|To process, please provide: a. Tax Returns b. Identification c. Statement of Approval Sally|Accountant|Approved Here, | is the delimiter. For Robert, I want "To process,…
Desmond
  • 1,047
  • 7
  • 14
2
votes
1 answer

Grouping legend by higher classification, filum and genus? ggplot2

Im want make better the legend() I am looking for the legend to be grouped according to a higher classification (phylum) but that at the same time the genus (Genus) is shown. Or make equal but only select the 20 Genus most abundant in each Filum I…
2
votes
2 answers

How to sort data in descending order based on every second value in R?

I am using dplyr for most of my data wrangling in R. Yet, I am having a hard time achieving this particular effect. Can't also seem to find the answer by googling either. Assume I have data like this and what I want to achieve is to sort…
bajun65537
  • 498
  • 3
  • 14
2
votes
1 answer

if_else with sequence of conditions

I have the following data: library(tidyverse) library(lubridate) df <- tibble(date = as_date(c("2019-11-20", "2019-11-27", "2020-04-01", "2020-04-15", "2020-09-23", "2020-11-25", "2021-03-03"))) # A tibble: 7 x 1 date 1…
deschen
  • 10,012
  • 3
  • 27
  • 50
2
votes
2 answers

use output of previous magrittr chains as arguments to further arguments

if I have the following example: library(text2vec) library(magrittr) reviews <- movie_review[1:10,] vocabInsomnia <- reviews$review %>% itoken(tolower, word_tokenizer, n_chunks = 10) %>% create_vocabulary %>% …
brucezepplin
  • 9,202
  • 26
  • 76
  • 129
2
votes
1 answer

Filter columns and repeatedly comparing two columns in pair using R

Given a df as follows, for each year's actual and predicted values, I need to check if current year's actual and predicted values with same directions comparing to previous year's actual values: df <- structure(list(code = c("M0000273", "M0000357",…
ah bon
  • 9,293
  • 12
  • 65
  • 148