Category "dplyr"

Creating custom Quantiles within data frame?

If i have the following table: tibble(year = c("2020", "2020", "2020","2021", "2021", "2021"), website = c("facebook", "google", "youtube","facebook", "

How to convert timestamp to date in each row of a column in R?

I have a column which list timestamps and I am in need of converting that to corresponding date for all rows in that column. Listing the code below app21_csv &

%>% .$column_name equivalent for R base pipe |>

I frequently use the dplyr piping to get a column from a tibble into a vector as below iris %>% .$Sepal.Length iris %>% .$Sepal.Length %>% cut(5) How

Using R to Calculate the time since binary output=1

I have binary data in a dataframe with a time feature and I'm looking to produce a dataframe like below with a new column "duration since =1". I was able to fi

Unexpected behavior with n_distinct inside pipe

I am trying to use the n_distinct function from dplyr inside a pipe in a function and am finding it to be sensitive to my choice of syntax in a way I didn't exp

dplyr: Replace multiple values based on condition in a selection of columns

I try to conditionally replace multiple values in a data frame. In the following data set, I want to replace in columns 3:5 all values of 2 by "X" and all value

Using dplyr and mutate to create new columns based on groups and last n rows

I have the following data frame as an example: match_id <- c("match_1", "match_1","match_1","match_2","match_2","match_2","match_3","match_3","match_3", "mat

Filtering using multiple variables and retaining those variables that meet criteria

I would like to filter using multiple variables in R. I got a way of doing so. How about if I only want to select the variables that meet the filtering criteria

pandas equivalent to mutate accros

I would like to perform following operation in Pandas: library(tidyverse) df <- tibble(mtcars) df %>% select(ends_with('t')) %>% head(3) # A

Mahalanobis difference by group with dplyr

I want to get a Mahalanobis difference for each set of two scores, after being grouped by another variable. In this case, it would be a Mahalanobis difference f

Modify a single cell value in dplyr

Let's say I have the following dataset: dat <- read.table(text="id_1 id_2 123 NA 456 NA NA 3

Conditional mutate - creating a new variable with coalesce

I'm scraping data from a website and depending on the structure of the page. I have an inner join in my final table that either joins clean on WON and LOST vari

Creating predicted vs observed confidence interval graph

Hello and thank you for you time and consideration, I'd like to recreate this graph with ggplot. The top blue dots are the predicted values from my fitted model

How to add sequence of numbers to each group of a data.frame?

I have a dataframe of US zipcodes and I want to add a sequence of numbers to each unique zipcode while repeating the rest of the rows. Right now, my data looks

using the uniroot function with dplyr pipes

I'm trying to utilize the uniroot function inside a piping scheme. I have root data by depth, and I fit a model for each crop-year set and put the fitted parame

using the uniroot function with dplyr pipes

I'm trying to utilize the uniroot function inside a piping scheme. I have root data by depth, and I fit a model for each crop-year set and put the fitted parame

Specify order after gather and spread

I want to keep the order of the output variables the same as the order they were created in the mutate statement. How do I accomplish this? It seems to be reor

Coalesce columns and create another column to specify source

I'm using dplyr::coalesce() to combine several columns into one. Originally, across columns, each row has only one column with actual value while the other colu

R Dataframe By Group Calculation

I have a dataframe like below (the real data has many more people and club): Year Player Club 2005 Phelan Chicago Fire 2007 Phelan Boston Pant 2

Automating conditional logic for database data checks in R

I am trying to do a large data check for a database. Some fields in the database are hidden, so when I am doing the datacheck, I need to ignore all hidden field