Category "dplyr"

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

How to left_join() two datasets but only select specific columns from one of the datasets?

Here are two datasets: (this is fake data) library(tidyverse) myfruit <- tibble(fruit_name = c("apple", "pear", "banana", "cherry"), number

How to look at differences between 2 columns in R

I just need to write some code that will look at the difference between the "est_age" and "known_age" columns in my data set. Then I need to know what percenta

max.col with the value not the index

If I have a matrix: mod_xgb_softprob$pred[1:3,1:3] [,1] [,2] [,3] [1,] 6.781361e-04 6.781361e-04 6.781422e-04 [2,] 2.022457e-07 2.

In dplyr using str_detect and case_when in R

This is my df: mydf <- structure(list(Action = c("Passes accurate", "Passes accurate", "Passes accurate", "Passes accurate", "Lost balls", "Lost balls (in o

Include 'blank' filters in dplyr filter chain in Shiny app

I have a shiny application with numerous user inputs including numericInput and textInput and pickerInput. These inputs are used to filter a dataframe. In my fi

separate_columns for tidyr

Let's say I had a survey question that read: What did you eat? [ ] apple [ ] pear [x] banana [x] grapes Now, I have the endorsed options as comma-separated st

Calculate Stock

Is it possible calculated stock using R? The formula is stock+purchase-sold. In this case first stock (row1) is 0, rg first result stockB1= 12 - 3 = 9 the secon

grouped data frame to list

I've got a data frame that contains names that are grouped, like so: df <- data.frame(group = rep(letters[1:2], each=2), name = LETTERS[1:4

Difference between pull and select in dplyr?

It seems like dplyr::pull() and dplyr::select() do the same thing. Is there a difference besides that dplyr::pull() only selects 1 variable?

R how to group part of overlapped values among rows?

I have a data frame that some rows that need to be further grouped by some of the overlapped values among rows col1, col2 a1, 2;3 a2, 2 a3, 3;4 a4, 4 a

How to fix the var(X) is now defunct

I used the following function to find standard error of variables. but when I run the same function now, it is not working. st.err <- function(x) { sd(

Taking only the maximum values of duplicate IDs for all columns of a data frame in R

I have data frame of 24525 rows and 22 columns. Last column is the ID column, other are numeric. Number of unique IDs is 18414 and some IDs are repeated more th

Using dplyr to conditionally replace values in a column

I have an example data set with a column that reads somewhat like this: Candy Sanitizer Candy Water Cake Candy Ice Cream Gum Candy Coffee What I'd like to do

Using dplyr to conditionally replace values in a column

I have an example data set with a column that reads somewhat like this: Candy Sanitizer Candy Water Cake Candy Ice Cream Gum Candy Coffee What I'd like to do

How to add a total distance column in 'flights' dataset? DPLYR, Group_by, Ungroup

I am working with 'flights' dataset from 'nycflights13' package in R. I want to add a column which adds the total distance covered by each 'carrier' in 2013. I

dplyr::select function clashes with MASS::select

If I load the MASS package: library(MASS) then load try to run dplyr::select, I get a error: library(dplyr) mtcars %.% select(mpg) # Error in select(`__pre

Calling user defined functions from dplyr::mutate

I'm working on a project that involves many different tibbles, all of which have a period variable of the format YYYYMM. Below is an example of how all my tibbl