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

Custom function: Return a tidyselect argument as character-string, without executing the argument

I would like to create a segment in my custom function where the input of the argument "evars" is returned as a character string, without executing/evaluating the argument. The argument is a tidyselect function used to extract specified columns from…
daems013
  • 45
  • 5
2
votes
1 answer

R printing each data.frame of a list into separate Tables with caption as data.frame name and description

Follow-up to my earlier question. (Thanks to @akrun for his help.) Want to print each data.frame of a list into separate Tables with caption as data.frame name and description from another object. My attempted code is given below. Not being able to…
MYaseen208
  • 22,666
  • 37
  • 165
  • 309
2
votes
1 answer

R printing each `data.frame` of a list into separate Tables with caption as `data.frame` name

Want to print each data.frame of a list into separate Tables with caption as data.frame name. My attempted code is given below. It produces Tables but with wrong captions. library(tidyverse) library(kableExtra) #> #> Attaching package:…
MYaseen208
  • 22,666
  • 37
  • 165
  • 309
2
votes
2 answers

Dataframe column looping and string concatenation based on conditional in R (pref dplyr)

I have a 2-column dataframe. First column contains a single entry of a class of items (in this case, vegetables). The second column is the incoming new_item, which are grocery items of different categories (meat, fruit, veg,…
Edmond Kwan
  • 157
  • 4
2
votes
1 answer

Replace missing values if previous and next values are consistent

I am currently working with time series data which looks something like the following: ID Var1 Var2 Var3 Var4 Var5 1 A NA A NA A 2 B C NA NA B 3 A A NA NA A 4 A B NA NA B 5 C NA B NA B df <- data.frame("ID" = c(1, 2, 3, 4, 5), …
tmako
  • 349
  • 2
  • 9
2
votes
1 answer

Purrr functional programming error when hitting blank values

Im sorry if this is a brainf*rt question - its probably a simple error handling. This code breaks when one of the variables hits a blank (in this case in the 'num_views' variable) - Is there a way to return an 'NA' for any blank values? I would be…
Robert Chestnutt
  • 302
  • 3
  • 13
2
votes
1 answer

R - Merge two elements of a list in an iterative pdf task

For a pdf mining task in R, I need your help. I wish to mine 1061 multi-page pdf files with the file names pdf_filenames, for which I would like to extract the content of the first two pages of each pdf file. So far, I have managed to get the…
2
votes
1 answer

Dynamic variable names within an ifelse-function

I have some problems writing a function that takes a dataframe and a variable name as arguments. Then the specified variable in the dataframe should be checked. How can I use the variable name within the ifelse-statement? # Some test data dat <-…
D. Studer
  • 1,711
  • 1
  • 16
  • 35
2
votes
1 answer

How to dynamically pass columns in tidyverse's across

Assuming the following data: df <- data.frame(id = 1:3, result1 = 4:6, result2 = letters[7:9], result1_label = "test label 1", result2_label = "test label 2") I now want to…
deschen
  • 10,012
  • 3
  • 27
  • 50
2
votes
1 answer

Standardize Rename with a Dictionary

I'm looking to standardize some code which deals with cleaning data which has different column names over time. The idea is to create a dictionary along with a function which searches if a given dataset has names in the dictionary, and then replaces…
spazznolo
  • 747
  • 3
  • 9
2
votes
2 answers

Convert a character to NA based on a condition in R dplyr

I have a data frame that looks like this library(tidyverse) df3 <- tibble(col1 = c("apple",rep("banana",3)), col2 = c("aple", "banan","bananb","banat"), count_col1 = c(1,4,4,4), count_col2 =…
LDT
  • 2,856
  • 2
  • 15
  • 32
2
votes
2 answers

Create lagged variables for consecutive time points only using R

I have an unbalanced panel (with unequally spaced measurement points) and would like to create a lagged variable of x by group (Variable: id) but only for consecutive time points. My data looks like this: # simple example with an unbalanced…
Mary B.
  • 125
  • 7
2
votes
1 answer

number of times specific value in each column R

I have: library(tidyverse) df <- tibble(one=c(1,1,1,2,2,2,3,3), log1 = c(TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE), log2 = c(TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE), log3 = c(TRUE, TRUE, FALSE, FALSE,…
frank
  • 3,036
  • 7
  • 33
  • 65
2
votes
2 answers

R dataframe - Top n values in row with column names

I want to sort rowwise values in specific columns, get top 'n' values, and get corresponding column names in new columns. The output would look something like this: SL SW PL PW Species high1 high2 high3 col1 col2 col3 dbl>…
jaykay
  • 71
  • 7
2
votes
1 answer

Using a list of models to make predictions over a list of results using lapply in R

I have a large list of models that I built using lapply with the following code (these lists are too long to show the whole data but I used the corresponding code to set the models up): table_list <- raw2 %>% group_by(Lake_name) %>% …
David Smith
  • 305
  • 1
  • 8