Category "dplyr"

Paste together results within case_when (if-else) statements

I want to paste together results within the same case_when statement (i.e., if multiple statements are true for a given row). I know that I could do something l

dplyr get linear regression coefficients

I'm wondering if there is a better way is to get linear regression coefficients as columns in dplyr. Here is some sample data. mydata <- data.frame( S

rewriting `summarise_all` without deprecated `funs`, using Simple list and Auto-named list

I'm trying to count the number of NA values in each of 2 columns. The code below works. temp2 %>% select(c18basic, c18ipug) %>% summarise_all(funs(sum

How to return the range of values shared between two data frames in R?

I have several data frames that have the same columns names, and ID , the following to are the start from and end to of a range and group label from each of the

Rename several columns using start with in r

I want to rename multiple columns that starts with the same string. However, all the codes I tried did not change the columns. For example this: df %>% renam

R Dataframe Filter Values

I have a dataframe looks like below: Place Time1 Time2 Time3 Time4 Time5 Time6 Time7 Time8 Time9 ... CA 0.2 0.3 0.1 0.

Extract text after first upper case or space

How can I extract all text after first space in a column where data is something like this structure(list(value = c("1.1.a Blue sea", "1.2.a Red ball")), row.na

Fill in missing variables of family relationship matrix

I have a dataframe of family relationships (parent, child, spouse, etc.) which is partially filled as per example below. I am trying to use R to fill in the mis

How to check if values in first dataframe are contained or match values in another dataframe

I am using R to work with some dataframes. My issue is related on how to check if values in a variable in a first dataframe match with values in another datafra

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`