Re: [R] Using Partial Column Matching for Mutate

2019-08-06 Thread Shawn Way
Frankly, this is great. I don’t really care if it base or tidy, I just need it to work. Thank you kindly! Shawn Way, PE From: Eric Berger Sent: Tuesday, August 06, 2019 8:30 AM To: Shawn Way Cc: r-help@r-project.org Subject: Re: [R] Using Partial Column Matching for Mutate ** External

Re: [R] Using Partial Column Matching for Mutate

2019-08-06 Thread Eric Berger
Hi Shawn, Here is a solution using base R (no dplyr). The only regex appears in the statement to get the common prefixes. colsPrefixes <- sub("_Planned$","",colnames(gross_test)[ grep("_Planned$",colnames(gross_test))]) f <- function(s) { gross_test[,paste(s,"Diff",sep="_")] <<- gross_test[,past