Category "dplyr"

How to left join two data frames conditionally - by rows that fall within a date range - and by two variables found in each data frame

I have two simulated data frames: d, created below, which has all the rows of longitudinal data for two different people. Each row has a start and end date. Som

Make a list out of frequencies, concatenating categories to that list

I am trying to adapt this solution, by onyambu: New data dat_in_new <- structure(list(rn = c("Type_A", "Type_B" ), `[0,25) east` = c(1269L, 85L), `[0,25)

Create new column based on presence/absence of string in other column by group

I have this dataset about vessels locations, where the same "id" can correspond to two levels. Corresponds to a defined category, such as "fishing" and may also

How to add new column with variable using mutate

How to add new column with variable? I have a problem must use variable to add column. library(dplyr) data(iris) x<-"newcol" iris %>% mutate(x="only te

Comparing Dates Across Multiple Variables

I'm attempting to figure out the amount of days in between games and if that has an impact on wins/losses, this is the information I'm starting with: schedule:

How do I assign group level value - based on row level values - to df using dplyr

I have the following decision rules: RELIABILITY LEVEL DESCRIPTION LEVEL I Multiple regression LEVEL II Multiple regression + mec

Pivot Longer in R Issues

I've looked quite a few different questions on here around Pivot Longer but I can't seem to figure out how to get my scenario to work. For example R Pivot multi

Randomizing within and across groups using group_by and sample

I'm running a study in which each participant will be presented with stimuli that have been randomized at two different levels: blocks (3 unique blocks) and tri

How to flag time-varying indicators with overlapping dates in a longitudinal data set?

I have a simulated data set with 5 rows, each representing a block of person-time, each with its own start and end date ('start' and 'end'). Each row has a visi

Create a new column based on multiple conditions in other columns in R

I have a data frame that has this structure: dat <- data.frame(col1 = sample(0:3, 10, replace = TRUE), col2 = sample(0:3, 10, replace = TRU

Converting column names so they can be put in an numerical order

I am trying to expand on this answer, by creating a solution that works both on the new_dat and the old_dat. New Data new_dat <- structure(list(`[0,25) east`

How to use created functions argument inside the code?

When I create a function and use arguments as variable names in group_by() function there is error: comb <- function(z,x,y) { df <- z %>% group

Create unique row values in new column based on matching criteria in R

I have a dataframe with one identifier column of unique values, and one column which contains specific criteria. I want to create a new identifier column of uni

Retain all columns after using group_by summarise, and mutatue dplyr on categorical variable and plot barplot with confidence intervals

I'm new to R. This is my dataset df <- tribble( ~Area_of_interst ,~Meds,~Response, "Internal Med", "asprin", "yes", "Inter

How to apply code to dataframe by condition?

I have the following dataframe: library(dplyr) library(tidyverse) library(concordance) Year <- c(2016,2016,2017,2019,2020,2020,2020,2013,2010,2010) Pf <-

How to use mutate() +across() only for specific rows

The data: df <- tribble( ~name, ~val.I, ~val.V, ~`val.%`, "Peter", 123, 12.4, 14, "Peter in %", 111, 532, 57, "Harald", 2222, 3333, 444, "Harald in

Summing across in a dataframe with condition coming from another column

this is not a very good title for the question. I want to sum across certain columns in a data frame for each group, excluding one column for each of my groups.

How to filter out a row if there are two consecutive instances of the same value?

I have a data frame with multiple similar sequences in which column Z has a string pattern containing "VALUE1" and "VALUE2" (only these two patterns matter) and

Multiples rows to one row in R [closed]

In R, I have a data frame with several values. I would like to have a data frame that transforms the data frame into a data frame with just on

Ways to select multiple columns in base R using the native pipe |>?

What are good ways to select multiple columns of a data frame in base R using the native pipe |>? (i.e., without the tidyverse/dplyr to reduce external depen