I have a dataset like this.
> dataset
| id | a | b | c | d |
|---|---|---|---|---|
| 1 | 10 | 1 | 30 | 50 |
| 2 | 5 | 0 | 5 | 60 |
| 3 | 20 | 1 | 18 | 90 |
| 4 | 103 | 0 | 20 | 80 |
| 5 | 16 | 1 | 56 | 100 |
And so on up to 'n' number of columns in relation to the requirement.
My colleagues in the research area carry out certain analyzes where what they give me as an input is a data frame. In which the row names correspond to the variables of interest for a new dataset.
Something like this.
> rownames(Features)
| a |
| b |
| d |
| a:d |
| b:d |
| b:c |
| a:c |
Where the colon (:) represents the "product of". So in order to continue working I need to include those products in the original dataset.
I have manually created a function that reproduces the multiplications in the following way (where x represents my original dataset):
Products<- function(x){x<- x %>% mutate(Product1=x$a*x$d)
x<- x %>% mutate(Product2=x$b*x$d)
x<- x %>% mutate(Product3=x$b*x$c)
x<- x %>% mutate(Product4=x$a*x$c)
return(x)}
However, given that the number of products to create is variable every time, I want to find a way to automate the creation of these column multiplications with the names that they give me as input. I'm sure my approach isn't the best, so any help is very welcome.