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
14
votes
3 answers

using tidyverse; counting after and before change in value, within groups, generating new variables for each unique shift

I am looking for a tidyverse-solution that can count occurrences of unique values of TF within groups, id in the data datatbl. When TF changes I want to count both forward and backwards from that point. This counting should be stored in a new…
Eric Fail
  • 8,191
  • 8
  • 72
  • 128
14
votes
2 answers

base R faster than readr for reading multiple CSV files

There is a lot of documentation on how to read multiple CSVs and bind them into one data frame. I have 5000+ CSV files I need to read in and bind into one data structure. In particular I've followed the discussion here: Issue in Loading multiple…
Lloyd Christmas
  • 1,016
  • 6
  • 15
14
votes
4 answers

How to find which polygon a point belong to via sf

I have a sf object that contains polygon information (precincts) for a metro area, obtained through a .shp file. For a given lat/lon pair, I want to determine which precinct it belongs to. I'm thinking I can utilize sf::st_contains() but am having…
kevinykuo
  • 4,600
  • 5
  • 23
  • 31
13
votes
5 answers

Keep top 3 values in a row, change everything else to NA

Using mtcars for reproduciblity (This is a row operation). I want to keep 3 values in a row based on their magnitude (so basically top 3 values would be having value, rest everything change to NA) I tried using pivot_longer converting to long then…
Vaibhav Singh
  • 1,159
  • 1
  • 10
  • 25
13
votes
1 answer

Which tidyverse functions return tibbles?

Some tidyverse functions return dataframes, but some return tibbles. I can't find any resources on which functions return which data type, and I can't see any real predictable pattern to it. Here are a few examples for…
astrofunkswag
  • 2,608
  • 12
  • 25
13
votes
2 answers

How to specify columns to exclude when retaining all distinct rows?

How do you retain all distinct rows in a data frame excluding certain columns by specifying only the columns you want to exclude. In the example below library(dplyr) dat <- data_frame( x = c("a", "a", "b"), y = c("c", "c", "d"), z =…
David Rubinger
  • 3,580
  • 1
  • 20
  • 29
13
votes
1 answer

read_csv() parsing error message, how to interpret?

I am in the middle of parsing in a large amount of csv data. The data is rather "dirty" in that I have inconsistent delimiters, spurious characters and format issues that cause problems for read_csv(). My problem here, however, is not the dirtiness…
Angelo
  • 2,936
  • 5
  • 29
  • 44
13
votes
4 answers

How to install Tidyverse on Ubuntu 16.04 and 17.04

I'm running Ubuntu 16.04 [now 17.04: see note in bold below] and R 3.4.1. I installed the latter this morning, so I presume it's the latest version. I want to install Tidyverse, which I've spent many happy hours with under Windows. But when I do…
12
votes
1 answer

How to pivoting dataframe consisting column with section and sub section In R

I have a below-mentioned dataframe: structure( list(ID = c("P-1", " P-1", "P-1", "P-2", "P-3", "P-4", "P-5", "P-6", "P-7", "P-8"), Date = c("2020-03-16 12:11:33", "2020-03-16 13:16:04", "2020-03-16 06:13:55",…
user9211845
  • 131
  • 1
  • 12
12
votes
4 answers

What does 'Can't use `!!!` at top level.' mean and how to resolve it?

I am trying to create a function for creating lollipop plots using ggplot2. I would like to pass all argument within ... to aes() within geom_point(). However, I'd like to exclude the size argument from passing onto aes() within geom_segment() (for…
Thomas Neitmann
  • 2,552
  • 1
  • 16
  • 31
12
votes
1 answer

What is the advantage of using library('tidyverse') instead of sub packages?

I was wondering what could be the impact on a large R (shiny) application if we call the tidyverse package. We usually call dplyr, tidyr, and so on separately. Any hints are welcome! Thanks in advance!
Joni Hoppen
  • 658
  • 5
  • 23
12
votes
6 answers

How to remove rows where all columns are zero using dplyr pipe

I have the following data frame: dat <- structure(list(`A-XXX` = c(1.51653275922944, 0.077037240321129, 0), `fBM-XXX` = c(2.22875185527511, 0, 0), `P-XXX` = c(1.73356698481106, 0, 0), `vBM-XXX` = c(3.00397859609183, 0, 0)), .Names = c("A-XXX",…
littleworth
  • 4,781
  • 6
  • 42
  • 76
12
votes
2 answers

How to Use na.rm=TRUE with n() While Using Dplyr's Group_by and Summarise_at

library(tidyverse) I'm stuck on something that should be so simple! Using the code below, all I want to do is group and summarise the three "Var" columns. I want counts and sums (so that I can create three percentage columns, so bonus if you can…
Mike
  • 2,017
  • 6
  • 26
  • 53
12
votes
2 answers

Create the SQL query "SELECT * FROM myTable LIMIT 10" using dplyr

Suppose I have a connection to an external database called con. I would like to use dplyr to reproduce this query SELECT var1, var2, var3 from myTable LIMIT 10 I have tried qry <- tbl(con, "myTable") %>% select(var1) %>% …
Adam Black
  • 337
  • 3
  • 13
12
votes
2 answers

Conditional filtering using tidyverse

I want to filter my data frame based on a variable that may or may not exist. As an expected output, I want a df that is filtered (if it has the filter variable), or the original, unfiltered df (if the variable is missing). Here is a minimal…
Tamas Nagy
  • 1,001
  • 12
  • 22