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

How to select the max value of each row (not all columns) and mutate 2 columns which are the max value and name in R?

This is the original dataframe. I want to know the max value between 'a' and 'b', and mutate max value and variable name as two columns. df <- data.frame(lon = c(102,103,104,105), lat = c(31,32,33,34), a =…
jackywang
  • 75
  • 6
2
votes
1 answer
2
votes
1 answer

group tibble rows by unordered combination of columns

Given the following tibble tibble(sample = c(1:6), string = c("ABC","ABC","CBA","FED","DEF","DEF"), x = c("a","a","b","e","d","d"), y = c("b","b","a","d","e","e")) # A tibble: 6 × 4 sample string x y
acvill
  • 395
  • 7
  • 15
2
votes
1 answer

Multiple sets of grouped bar charts (on the same plot) without using "transforms" in r plotly

Code: library(plotly) library(tidyverse) df <- data.frame(protein = c("Chicken", "Beef", "Pork", "Fish", "Chicken", "Beef", "Pork", "Fish"), y1 = c(3, 24, 36, 49, 7, 15, 34, 49), y2 =…
2
votes
1 answer

How to filter data frame based on criteria spanning multiple columns using dplyr in R

I have a data frame containing 92 variables and 1900 observations. Essentially I have species ID as my variable of interest and relative abundance as the other variables. Columns 69:92 (23 columns) are quality control variables that range from…
FredrikM
  • 23
  • 3
2
votes
2 answers

How to show the number of dropped observations in R?

For different analysis, I use different samples, but I need to make it transparent how the sample came about. Stata shows me "XX observations dropped" after each drop command. Is there a way to get R to state the number of observations dropped in…
KPol
  • 23
  • 4
2
votes
2 answers

I lose the constant variables (including id) when using pivot_longer with multiple variables

I try to reshape the following country region abc2001 abc2002 xyz2001 xyz2002 Japan East Asia 1 2 4.5 5.5 to the following country region year abc xyz Japan East Asia 2001 1 4.5 Japan East Asia 2002 2 5.5 actually there are…
2
votes
1 answer

Extract the first N observations of groups according to another dataframe

I would like to extract the first observations of different groups from a dataframe. The number of observations comes from another dataframe. Here is an example: In dataframe "x" there are different groups of animals with their names. x <-…
RKF
  • 131
  • 7
2
votes
2 answers

How to pivot multiple columns at the same time?

I have a data frame with exam questions organized as you see below in input. I'm trying to organize it in a tidy way as displayed in output. In input you can see student's ID, their answer to the specific item suffix = ".text", their score for that…
Ruam Pimentel
  • 1,288
  • 4
  • 16
2
votes
1 answer

How can I multiply all the values within a column range and row range?

I have a df that looks like this: Name No1 No2 No 3 Jack 10 20 30 Eli 10 20 30 Mae 10 20 30 Jack 10 20 30 I want to multiply all values by a factor of 10 in columns 2:4 (so all columns excluding the Name column) and I only want to…
Brenda Thompson
  • 327
  • 2
  • 9
2
votes
2 answers

insert space after each flextable in r (Rmd)

i have this problem: Problem: I have multiple flextable objects in a same r chunk: mtcars %>% select(1:3) %>% head() %>% flextable() mtcars %>% select(1:3) %>% head() %>% flextable() But when i knit the Rmd in a…
2
votes
0 answers

How to prevent tibble from converting (unrecognized ?) utf-8 characters?

(related to How can I make R maintain utf8 encodings? but not quite the same issue; also related to Force character vector encoding from "unknown" to "UTF-8" in R but not exactly the same, as in my case the conversion seems to happen upon creating a…
jfmoyen
  • 495
  • 2
  • 11
2
votes
1 answer

How to arrange nested data (i.e., data with parenting) in R?

I have a dataset with multiple levels: Categories (e.g., "Countries") Countries (e.g., "USA") Cities (e.g., "New York") Counties (e.g., "Manhattan") Places (e.g., "Times Square") Each row (except for LVL 1 entries) is linked to a parent a level…
diggi2395
  • 185
  • 8
2
votes
1 answer

create multiple cross tables with one-line code function with gtsummary

i'm having the following problem: Context: I'm using gtsummary to explore frequencies in a dataframe using cross variables. Here's my desire output: So that i have a main variable tobgp and its cross by multiple variables like agegp and…
2
votes
2 answers

How many of each distinct item in a column is assigned to each distinct item of another column?

I am trying with dplyr functions group_by() and summarize(), count() but I can not figure out how to do : How many of each color is assigned to each id? ie : id = 2 has 1 b and 1 r. id 3 has only 1 r ,... df = data.frame(color =…
Mathica
  • 1,241
  • 1
  • 5
  • 17