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

How do I filter on a rolling basis?

How do I conditionally filter/select relevant observations on a rolling basis? Groups 1 to 52 are the baseline. Then in Groups 53, I want to filter out all the IDs that appeared in Groups 1 to 52 Then for Groups 54, I want to filter out all the IDs…
HITHERE
  • 136
  • 6
2
votes
1 answer

grouped summarize still gives result for each individual row

I have the following data: library(tidyverse) df <- data.frame(id = c(1,1,1,2,2,2), x = rep(letters[1:2], each = 3), y = c(3,4,3,5,6,5), z = c(7,8,9,10,11,12)) I now want to summarize the data by…
deschen
  • 10,012
  • 3
  • 27
  • 50
2
votes
1 answer

Using pivot_wider in a function with named variable from function argument

I am trying to use pivot_wider inside a function. The values are not uniquely defined, so I need to specify the values_fn argument of pivot_wider, which should return a list. The column for values_fn is the argument of the function. Here is a…
IrisOren
  • 69
  • 1
  • 1
  • 6
2
votes
3 answers

Remove part of a string based on another column in R

I have a large dataset that looks like this. I want to remove a certain number of strings from the fruits columns indicated by the remove_strings column. library(tidyverse) df <- tibble(fruits=c("apple","banana","ananas"), …
LDT
  • 2,856
  • 2
  • 15
  • 32
2
votes
2 answers

How to get rid of annotations on faceted graph?

Problem I am trying to label the left facet side of my graph while leaving out the annotations on the right side. Data Here are my libraries and data: #### Libraries #### library(tidyverse) library(ggpubr) library(plotly) #### Dput #### emlit <-…
Shawn Hemelstrand
  • 2,676
  • 4
  • 17
  • 30
2
votes
1 answer

Can I reshape and fill a number in tibble() with R?

I am a very novice in R programing + tidyverse. As you can see below, I want to fill the NAs corresponding to the Item name of each row and column. And then I want to leave only one row per a district name. How could I do this in tidyverse or just…
2
votes
2 answers

How do I find the interval with the most values in a time series data frame with a lot of NAs?

I have a time series data frame consisting of 980 observations and 980 variables. There are a lot of NAs in the data set. I need to find the perfect interval with the most data (variables) in a given amount of observations. Let's say I want to limit…
trappey
  • 21
  • 1
2
votes
1 answer

How to evaluate conditions met on previous values within a group in a data.frame in R

Thanks in advance for your help on this question you lovely people of SQ , I have a dataset that looks like this: library(tidyverse) name<-c("AAA","AAA","AAA") value<-c(1:3) order<-c(2,3,6) tag<-c(0,0,0) …
R_Student
  • 624
  • 2
  • 14
2
votes
1 answer

Dplyr Arrange Giving Error when Sorting by more than 1 Column

I am getting this error using "arrange" from dplyr. I am trying to sort in descending order on 2 variables. Error in `dplyr::arrange()`: ! `desc()` must be called with exactly one argument. I have never had this problem before. Could there be a…
bodega18
  • 596
  • 2
  • 13
2
votes
3 answers

Match one dataframe based on a range in another dataframe in R tidyverse

I have two large datasets that want to match with each other library(tidyverse) df1 <- tibble(position=c(10,11,200,250,300)) df1 #> # A tibble: 5 × 1 #> position #> #> 1 10 #> 2 11 #> 3 200 #> 4 250 #> 5 …
LDT
  • 2,856
  • 2
  • 15
  • 32
2
votes
1 answer

Create Polygons by Category in sf file R

I have a large set of coordinates from the critical and endangered habit federal registry. I'm trying to digitize these maps for analysis. Here's a sample of the data as an…
2
votes
1 answer

Separate columns that contain an unequal mixture of numbers and text in R

I have a very odd data frame that looks like this library(tidyverse) df <- tibble(position=c(100,200,300), correction=c("62M89S", "8M1D55M88S", "1S25M1P36M89S")) df #> # A tibble: 3 × 2 #> …
LDT
  • 2,856
  • 2
  • 15
  • 32
2
votes
3 answers

Generate a random variable by id in R

I want to create a random ID variable considering an actual ID. That means that observations with the same id must have the same random ID. Let me put an example: id var1var2 1 a 1 5 g 35 1 hf 658 2 f 576 9 d 54546 2 dg 76 3 …
Amc
  • 131
  • 8
2
votes
2 answers

Convert to matrix but keep one diagonal to NULL in R

I have a huge dataset and that look like this. To save some memory I want to calculate the pairwise distance but leave the upper diagonal of the matrix to NULL. library(tidyverse) library(stringdist) #> #> Attaching package: 'stringdist' #> The…
LDT
  • 2,856
  • 2
  • 15
  • 32
2
votes
2 answers

Replace NA's in a numeric column with string label "not significant"

Ï want to replace NAs in certain columns of my data frame that are numeric with a string tag - "not significant". I tried the following but got an error library(dplyr) library(tidyr) df_inu <- df_inu %>% mutate_at(vars(a, b, c), ~replace_na(.x,…
Ekow_ababio
  • 163
  • 9