I have a data set with 5 different variables (e.g., a, b, c, d, and e). I want to have simple code (preferably with the tidyverse) that allows me to take the mean for each possible combination of the variables. For example, the mean of "ab", "ac", ..., all the way to "abcde". Is there a simple way of doing this?
All I've tried is manually creating the code for each variable. However, it seems like something like a loop would be more appropriate.
For example, if my data looked like this:
a <- rnorm(10, 0, 1)
b <- rnorm(10, 0, 1)
c <- rnorm(10, 0, 1)
d <- rnorm(10, 0, 1)
e <- rnorm(10, 0, 1)
data <- cbind.data.frame(a,b,c,d,e)
I want the data to look like the output as if I had done this for each combination of a, b, c, d, e:
data$ab <- (data$a + data$b)/2
.
.
.
data$abcde <- (data$a + data$b + data$c + data$d + data$e)/5