I am trying to create interaction variables for all 20 variables in a dataframe, so I would have in total 20 base variables and 380 interaction variables. For any single variable, I am able to create a dataframe of 19 variables by using:
in_sample[3:22] %>%
transmute(across(.cols = -c(frpm_frac_s), .fns = function(x){x*frpm_frac_s}))
But I am unable to iterate across the columns. I tried to use map over a vector of column names but am unable to get the function inside map to read as.symbol(character). Here is a sample of my data from dput:
structure(list(frpm_frac_s = c(0.870400011539459, 0.904699981212616,
0.98089998960495, 0.838800013065338, 0.919900000095367, 0.837700009346008,
0.84799998998642, 0.925999999046326, 0.963900029659271, 0.887899994850159
), enrollment_s = c(364, 608, 571, 705, 566, 838, 421, 757, 693,
535), ell_frac_s = c(0.46000000834465, 0.334000021219254, 0.300999999046326,
0.209999993443489, 0.706999957561493, 0.552999973297119, 0.412999987602234,
0.359000027179718, 0.726000010967255, 0.646999955177307), edi_s = c(8,
38, 39, 37, 11, 35, 15, 39, 9, 4), te_fte_s = c(23, 22, 20, 25,
24.5, 36, 18, 30.2999992370605, 24.3999996185303, 19)), row.names = c(NA,
10L), class = "data.frame")
When using:
in_sample[3:22] %>%
transmute(across(.cols = -c(frpm_frac_s), .fns = function(x){x*frpm_frac_s}))
I get:
structure(list(enrollment_s = c(316.825604200363, 550.057588577271,
560.093894064426, 591.354009211063, 520.663400053978, 701.992607831955,
357.007995784283, 700.981999278069, 667.982720553875, 475.026497244835
), ell_frac_s = c(0.400384012571335, 0.302169812922072, 0.295250895935631,
0.17614799724412, 0.650369261028242, 0.463248082799339, 0.350223985351086,
0.33243402482605, 0.699791432103968, 0.574471256869984), edi_s = c(6.96320009231567,
34.3785992860794, 38.255099594593, 31.0356004834175, 10.118900001049,
29.3195003271103, 12.7199998497963, 36.1139999628067, 8.67510026693344,
3.55159997940063), te_fte_s = c(20.0192002654076, 19.9033995866776,
19.617999792099, 20.9700003266335, 22.5375500023365, 30.1572003364563,
15.2639998197556, 28.0577992646217, 23.5191603559875, 16.870099902153
)), row.names = c(NA, 10L), class = "data.frame")
I would like to do this for all variables and then cbind them together. Thank you for your help.