Assuming I have a data with three individuals A
, B
, and C
, and each of them has two characteristics, "year of school"(YS
) and "number of siblings"(NS
). Thus, the dataset X
looks like as follows:
id <- c("A", "B", "C")
YS <- c(6, 9, 8)
NS <-c(1, 0, 3)
X <- data.frame(id, YS, NS)
Now I have to re-organize the data set based on all possible combination of A
, B
, and C
, which means there will be 2^3-1 combinations. More precisely, the combinations are: A
, B
, C
, AB
, AC
, BC
, ABC
, and a null
combination (i.e., 2^3-1 combinations). In addition to combine the individuals, I also have to calculate the value of each characteristics for each combination. For instance, the values of YS
and NS
for the combination AB
are 15 and 1. For another instance, the values of YS
and NS
for the combination ABC
are 23 and 4.
I kind of understand to use the code expand.grid
to generate the possible combinations, but I don't know how to combine the values of characteristics at the same time. Can anyone help? Thanks.