library(tidyverse)
library(rlang)
(mytable <- data.frame(
a=1:2,
b=2:3,
c=3:4,
x=5:6,
y=7:8,
z=9:10
))
ncm <- ncol(mytable)
(first_cols <- seq_len(ncm/2))
(second_cols <- setdiff(seq_len(ncm),first_cols))
first_half_names <- names(mytable)[first_cols]
second_half_names <- names(mytable)[second_cols]
(step_1 <- map2(first_half_names,
second_half_names,
\(x,y) paste0(x,"*",y) ))
(step_2 <- map2(first_half_names,
second_half_names,
\(x,y) paste0(x,y) ))
(step_3 <- rlang::parse_exprs(paste0(step_1,collapse=";")))
names(step_3) <- step_2
step_3
mutate(mytable,
!!!(step_3))