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

R, pivot wide to long while changing column names

I have data like this: df<-structure(list(fname = c("Linda", "Bob"), employee_number = c("00000123456", "654321"), job_role = c("Dept Research Admin", "Research Regulatory Assistant" ), ActiveAccount = c("Yes", "Yes"), CanAccess = c("No", "No"), …
Joe Crozier
  • 944
  • 8
  • 20
2
votes
2 answers

How to find the mean of multiple columns based on a second dataset?

Problem I need to use a dictionary dataset to determine which columns from a different dataset I should calculate the mean. Data I will illustrate my case with the iris dataset (a dataset already in R). I have two datasets: The actual data - like…
Ruam Pimentel
  • 1,288
  • 4
  • 16
2
votes
2 answers

Nested list to dataframe using tidyverse

I have a nested list from reading a JSON that stores logging info from a video game. The time element of the list is a simple vector, while inputManagerStates and syncedProperties are lists that may contain 0 or more elements. I am trying to get the…
Claudiu Papasteri
  • 2,469
  • 1
  • 17
  • 30
2
votes
1 answer

r successive filtering with n arguments in a list

I am trying to apply successive filters on a dataframe without knowing in advance the number of filter or their arguments. Arguments are stocked in a list. With 1 or 2 filters, i can do it with purrr. For instance with 2 filters : require(tidyverse)…
adouet
  • 23
  • 3
2
votes
3 answers

match data frames based on multiple columns in R

I have two huge datasets that look like this. there is one fruit from df2, PEACH, which is missing for any reason from df1. I want to add in df1 the fruits that are missing. library(tidyverse) df1 <- tibble(central_fruit=c("ananas","apple"), …
LDT
  • 2,856
  • 2
  • 15
  • 32
2
votes
2 answers

Merging different data frames in R to eliminate NAs

I'm currently working on a longitudinal data base in R. Therefore, I have a lot of missing values, because the values of the variables which have been unchanged since the last interview are not added in the new database. For example in the first…
Jpaete
  • 59
  • 4
2
votes
2 answers

How to calculate the sum of distinct observations in R dplyr

I am quite puzzled. While I know how to count the sum of distinct_values per group with the n_distinct(), its seems challenging to me at the moment to find the sum of the unique of the unique observations. I want to group by id, and then sum each…
LDT
  • 2,856
  • 2
  • 15
  • 32
2
votes
2 answers

How to aggregate a data frame based on the max value of the group in R

I have a large data with many groups that looks like this. I want in each group to use the fruit with the most counts as the central fruit, and aggregate the other fruits based on it! library(tidyverse) df <- tibble(col1 = c("apple","apple","pple",…
LDT
  • 2,856
  • 2
  • 15
  • 32
2
votes
0 answers

total() in tab_cols only sum up to one, any suggestion?

Suppose I have dataframe 'y' WR<-c("S",'J',"T") B<-c("b1","b2","b3") wgt<-c(0.3,2,3) y<-data.frame(WR,B,wgt) I want to make column percentage crosstab with B as row, WR, and total of WR as columns using expss function library(expss) y %>%…
Szicocs
  • 21
  • 2
2
votes
1 answer

R Function Conditional Syntax

Can someone help me with syntax for a function? The script works fine when not embedded in another function: library(tidyverse) library(rvest) library(xml2) library(haven) library(labelled) redcap1 <- structure(list(record_id = structure(c("1",…
wdefreit
  • 51
  • 3
2
votes
1 answer

Plotting continuous distribution in horizontal bar plot

This was my earlier question where it was solved using multiple distribution. I want to plot the continuous variable like age or tumor mutation burden as shown in first figure with a range like a window such 20-30 age group or some mutational burden…
PesKchan
  • 868
  • 6
  • 14
2
votes
3 answers

Recode variable based on length

I have a large dataframe with a structure like this: id v1 v2 v3 v4 v5 1 1 1 98 1 1 2 1 1 1 1 1 3 4 1 0 22 1 4 5 1 1 1 1 5 1 1 90 1 1 I would like to move from v2 all the way to v5 and if the variable value is greater than 1…
EGM8686
  • 1,492
  • 1
  • 11
  • 22
2
votes
1 answer

Unique combinations by group

I have the following data frame structured in terms of 3 variables, i.e Location, Latitude, and Longitude within every single group. I would like to calculate the euclidean distance between all unique location combinations within each group. So for…
9834
  • 21
  • 2
2
votes
3 answers

Adding new variables to existing data that correlate with one or two existing ones

How can I add two more variables with the following conditions? Variable "c" that has a 0.7 correlation with variable "a". If possible, variable "d" that correlates simultaneously with "a" and "b". Simulated data n = 100 d = tibble(a = rnorm(n,…
st4co4
  • 445
  • 3
  • 10
2
votes
4 answers

How to return an 'untidy' dataframe summary of multiple standard statistics arranged by row for each column of a dataframe in R?

With Pandas in Python there is the describe() function that returns the summary statistics for a dataframe. The output is not in a 'tidy' format for simple manipulation with the tidyverse summarise function but it is in a nice format for…