# Tidyverse Questions

Ad

## regex from stringr::str_detect works, but the same regex from tidyselect::matches returns an error

I'm confused about this inconsistency in the tidyverse and am not sure what's going on. test data: test <-

## get the no. of observations in every level of factor after grouping by factors

In the data arthritis of package 'vcd', after grouping by treatment and sex, i would like to get the no. and percentage of observations in every

## 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

## tidyverse solution for multiplying columns by a vector

I looked for solutions here: multiply columns

## 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

## Extracting specific variable names into a single variable

I would to pick out any variable with ## in each row then store such variables in the vars_extract variable. any idea?

## How to filter by multiple range of dates in R?

Thank you, experts for previous answers (how to filter by range of dates in r?)

## Error in using custom vectorized function in mutate/case_when

Below is a simple code to reproduce the error. i define a simple function, vectorize it with another function using purrr::map, and

## Convert dataframe so that it can be consumed by geom_line()

I need to convert a dataframe to a tibble like structure so that it can be consumed by geom_line() (ggplot2) to create a line plot.

## 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,

Ad

## 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

## How to automatically transform columns into objects in R?

I need that each column of my dataset become an object named with that column's name and containing its values as the object value. i know

## How to pivot_longer same columns multiple times?

Data i tried googling and searching so for the answer for this, but the answers typically just state how you can separate columns into

## variable masking in tidyverse programming in R

It is hard to reuse code in functions. i subset .data with [[ however received splicing error. i provide an example and the a solution

## geom_text change factor order of facet plot

I am trying annotate individual plots of a facet plot. i have set the order to 2008, 1999 using factor levels. but when i add the geom_text to the

## R - Filter data to only include date X and following date

I have data structured like below, but with many more columns. i need to filter the data to include only instances where a person has a

## calculating counts and percentages of a variable

I am trying to create a count of the number of observations and extract percentages from those counts. i have data that looks like

## Way to avoid nested ifelse statement in R

I have a dataframe that includes various ages and a value for each age. i would like to classify the different ages into broader age groups. to do

## Mutate case_when in R to create a column of time periods per participant

I have tested participants at three points in time. i have the dates at which they were tested. i want to make a column which levels are first,

## R : How to extract the factor levels as numeric from a column and assign it to a new column using tydyverse?

Suppose i have a data frame, df df = data.frame(name = rep(c("a", "b", "c"), each = 4))

## Tranforming dates into Weeks and Fortnights by Months using lubridate

I want to transform dates into weeks and fortnights by months using lubridate r package. my working example is

Ad

## lubridate: Finding weeks within months

I want to find weeks within months (separate numbering of weeks within months) using lubridate r package. my minimum

## Convert grouped data in dataframe to documents in preparation for word2vec

I'm trying to replicate what the author of

## How to list.files() until n level deep subdirectory in R

I have a very complex organisation of folders, and here is a simplified version of it.

## In R, how can I filter out specific values in an array using dplyr's piping operator (%>%)?

How can i use the dplyr/magrittr piping operator (%>%) to filter/subset an input array and remove a

## R, rate of growth, different time

I have the following example of dataset for a biology project. i want to compute a rate of growth of number between 4th january and 2nd of

## Returning rows prior to conditional filter?

I'm trying to fix some issues with data i have. the dataset is made up of a list of dataframes, each representing an individual. i have created a

## Break a small sentence in multiple rows with a single string each in R dplyr

I have a data frame that looks like this library(tidyverse) data=data.frame(pos=c(172367,10),

## Using Shiny and checkboxGroupInput to update a table via bind_rows or rbind and using if else statements

I have three tables (math, science, and literature results). i would like to have a "dynamic" table that updates some columns when

## purrr: element-wise length comparison of multiple lists?

I have three lists with 2 elements each. how do i check whether every element has the same length in every list? preferably using purrr. thank

## Extract strings based on a database in R dplyr

From my data i want to extract the strings that are between the l and r string from my database. my database includes 4 different l and r

## Creating new column by splitting a `chr` column, finding unique values, sorting them, removing certain values, and combining them back into one string

I'm working in r, using tidyverse and dplyr functions to generate new columns, but i'm running into a wall when trying

Ad

## Error in passing variable names to a function in R

I'm working with excel files which have both text and numerical data, tracked by an id variable whose name has a space in it. something like

## str_replace to a particular position

I am trying to clean a variable about income that comes from an historical database. i would like to replace all "£"

## How to continue tidyr/dplyr/tidyverse %>% commands to the next line?

I have a long command with a long line of dplyr/tidyr commands: object %>% mutate() %>% select() %>% separate() %>%

## Using R to Rearrange Data

I am working on some data in r. for reproducibility, the data is as follows: month,source,amount1,amount2,total

## Count the number of observations across multiple columns and create new categories

I have data like these: id color_1 color_2 color_3 color_4 1 blue na na na 5 green

## Expand dataset by count column in Dplyr

I have a dataset as follows: library(tidyverse) df <- data.frame( report_date = c("2020-03-14",

## Using map on specific column in list?

I'm trying to split a dataframe in a list of dataframes and then sort each dataframe by a specific variable using map(). i thought my

## Read in CSV files and Add a Column with File name

Assume you have 2 files as follows. file_1_october.csv file_2_november.csv the files have identical columns. so i

## How to summarize a unique value of a numeric variable within dplyr

Data: structure(list(month_name = c("september", "september", "september", "september",

## Is there a clean way to compose sequences into there subsequences in the tidyverse?

I have the following simple dataframe. i would like to find a clean tidyverse solution to decompose each sequence by row into its subsequences. i

## How to extract a string of unknown length between two delimiters in R

I have a data frame containing a column with user's email addresses. the format of the email address could be anything. i need to create a new

Ad

## Animation time with gganimate

I want to make a plot animate. i need that the points appear and disappear, but only make that the movements of points. set.seed(1)

## How to create a Weighted Sum Score based on a second dataset for specific variables

I have to create a weighted sum score (wsum) based on several variables. for instance, mydata has three variables (a, b, and c). i

## Rename multiple columns by extracting contents in parentheses for a list of dataframes

Given data and code as follows, i'm able to generate a list of dataframes dfs: library(data.table) library(purrr)

## Groupby one column and calculate lag difference of monthly, quarterly mixed data's current period values with previous one using R

Assuming i have a panel data as follows, which was edited from

## How do I calculate Euclidean distances across NA values in r

I have a date frame like this individual <- c("1",na,na,na,na,na,na,na,"1","1") x <-

## Unexpected dplyr::bind_rows() behavior

Short version: i'm encountering an error with dplyr::bind_rows() which i don't understand. i want to split my data based on

## How to sort data in descending order based on every second value in R?

I am using dplyr for most of my data wrangling in r. yet, i am having a hard time achieving this particular effect. can't also seem

## rbind/bind_rows two unequal data.frames

Below, i wonder how to rbind dat2 to dat1 such that i can achieve my desired_output below?

## Trouble with an R function for making a ggplot2 graph and optionally facetting with user-specified columns

I'd like to write a function in r for making some graphs and, optionally, facetting those graphs by whatever column the user inputs. i'd prefer to

## How to make distinct variables their own columns in ggplot2?

So i am attempting to replicate the following plot:

## How to select row with exactly only 2 unique value with tidyverse?

What i have: library(magrittr) set.seed(1234) what_i_have <- tibble::tibble( a = c(0, 1)

Ad

## Filter columns if certain strings are contained and convert these columns' data type using R

For iris dataset, let's say if i need to convert columns 'sepal.length', 'petal.length', 'petal.width''s data type to

## Reshape long dataframe to wide and rename new columns by using one column as prefix

Given a dataframe df as follows: df <- structure(list(code = c("m0000273", "m0000357",

## Structure of variables not recognised when dataframe is a tibble

I have made a function which assesses the structure of an input variable and then performs conditional descriptive statistics depending on what

## How to subset windows in a dataframe using start- and end-values from another dataframe in R?

I have a dataframe of timeseries data, df1, that i need to extract a number of 'windows' from in r. the start- and end-points for the

## Remove duplicates based on few columns and keep numeric numeric value if any and keep NA if there is no numeric in R

I have a dataframe below and i want to remove duplicates based on columns country and year, and keep the non na values for the columns 3 to the

## compare sets of columns in R dataframe and keep one value from each set of two columns

Basically, i have a large dataset with many different variables. the data is ordered in pairs (2019 and 2020) and for some variables for neither

## How to use group_by() with rep_len() r

Let me know if i need a dummy example for this but essentially i have a df of subgroups, each subgroup a different length (typically 30-35k

## How to separate "." delimited columns with tidyR

I think i am missing something important. every time i am trying to separate a column which has "." delimiter i fail. does anyone

## Inner_join on NSE

I want to write a function which joins two tibbles, with the 2nd tibble's joined column specified in the function's args. i have

## R: How to Intersect multiple vectors that gives all possible combination

How to intersect multiple vectors that gives all possible combination here is dummy data: set1 <- c("g1",

## Read dataframe from list in multiple RData files

I have a bunch of rdata files (1.rdata, 2.rdata... 100.rdata) all containing three list elements, "x", "y" and "z".

Ad

## Difference in days between two dates in R using dplyr and lubridate?

Looking to do the sql equivalent of datediff in r? basically, i want this calculation in r delivery date expected date

## How to attach newly generated variable by group or category to original dataset

I have a following dataframe (df) and generated a variable of summation of sales by industry (ksic2). i want to attach this new variable to the

## Using cut.Date and Starting Weeks on Saturday in R

I currently am aggregating data in exactly 4-week intervals, but i need the weeks to start on saturdays. i am using the cut.date line

## How to make a case crossover data in r

Creat a reproducible data set.seed(20220105) begin = as.date('1994-01-01') end = as.date('1994-12-31') date_seq = seq(from =

## Create a new column based on a dictionary using R

For the following dataframe d, i'm trying to create a new column by replacing col1 using a dictionary

## Find differences in character column in R

I have a dataframe with icpm codes before and after recoding of an operation. df1 <- tibble::tribble(~ops, ~opsalt,

## Extract a single value from a dataframe/tibble the tidy/dplyr way?

I know a few ways to get a single value out of a dataframe/tibble. library(dplyr) start_date <- tibble::tribble(

## Find min and max of a column given an ordered index in Dplyr

I have a vector and i add his indexes like it follows: library(tidyverse) ## create the vector vector_ex <- c(44, 30, 24, 32,

## Count how many times strings from one data frame appear to another data frame in R dplyr

I have two data frames that look like this: df1 <-

## R - identify cols that contain any of a values set

I have a dataframe like this df <- data.frame(col1 = c(letters[1:4],"a"),col2 = 1:5,col3 = letters[10:14]) df col1

## Conditional values using if else within shiny app using tidyverse and dplyr to group and filter a dataset

I have a simple shiny that presents descriptive statistics using reactive. however, i would like to use ifelse within tidyverse pipe

Ad

## How to convert long date frmat

I have dataframe with a date in this format "sun dec 26 2021 08:10:14 gmt+0100" see the data frame

Ad

## Blog Categories

Ad