I have a data frame with two columns: LOOKUP
which contains an index number, and the other, VALUE
which holds a string associated with that number:
LOOKUP VALUE
1000 Apple
100 Banana
10 Grape
1 Orange
Shown below in R code:
dat <- data.frame(LOOKUP= c(1000, 100, 10, 1),
VALUE = c("Apple", "Banana", "Grape", "Orange"))
In this example, there are 15 possible sums of the lookup value:
- 4 sums where only one number summed (1000, 100, 10, 1)
- 6 sums of two numbers (1000 + 100, 1000 + 10, 1000 + 1, 100 + 10, 100 + 1, 10 + 1)
- 4 sums of three numbers (1000 + 100 + 10, 1000 + 100 + 1, 1000 + 10 + 1, 100 + 10 + 1)
- 1 sum of four numbers (1000 + 100 + 10 + 1)
These sums are used to understand, for lack of a better description, what fruits are in a cart. For example, if the sum = 1100, we know that the cart has an apple and a banana. Does anybody know how I would do this for all possible combinations in my set? My desired output is a new data frame along the lines of:
SUM VALUES
1111 Apple, Banana, Grape, Orange
...
1100 Apple, Banana
...
11 Grape, Orange
1 Apple