How can I replace one term in an R formula with two?
问题 I have something along the lines of y ~ x + z And I would like to transform it to y ~ x_part1 + x_part2 + z More generally, I would like to have a function that takes a formula and returns that formula with all terms that match "^x$" replaced by "x_part1" and "x_part2". Here's my current solution, but it just feels so kludgey... my.formula <- fruit ~ apple + banana var.to.replace <- 'apple' my.terms <- labels(terms(my.formula)) new.terms <- paste0('(', paste0(var.to.replace, c('_part1', '