Thanks in advance for any advice. As part of a study, I need to:
Part 1:
I need to create a .csv dataset (or r data frame?) that produces all possible combinations of 10 different variables. Each of the 10 variables has either 2 (i.e., binary 0,1) or 4 levels. I think this should be possible easily in both excel and r, but r would be preferable. They are provided in the table below:
For example, the first set of combinations would keep "druga_LIFE" at 0.5 and then would cycle through all combinations of the other variables, then it would follow by fixing "druga_LIFE" at 1 and cycling through all other combinations of variables. Eventually, it would move on to fix "druga.NEED" at 0 changing other variables, then at 1 and so on.
The dataset should be a full set of combinations with no repeat combinations.
I understand there is a large number of possible combinations - this is as expected, but I don't think this should be too difficult to compute.
Part 2:
I then need to go through this dataset, selecting only the possible combinations where:
- "druga.LIFE" is the same as "drugb.LIFE"
AND
2)"druga.NEED" is the same as "drugb.NEED"
I think this should be simple with the dplyr package in R.
I have created the df in r, but do not know how to begin with cycling through to produce all possible combinations.
#DATASET OF ALL POSSIBLE CHOICE SETS#
#Creating the Vectors of choices
DrugA_LIFE <- c(0.5, 1, 2,5)
DrugA_NEED <- c(0,1)
DrugA_CERT <- c(0, 0.2, 0.4, 0.6)
DrugA_RISK <- c(0.1, 0.2, 0.4, 0.6)
DrugA_WAIT <- c(0, 0.5, 1, 2)
DrugB_LIFE <- c(0.5, 1, 2,5)
DrugB_NEED <- c(0,1)
DrugB_CERT <- c(0, 0.2, 0.4, 0.6)
DrugB_RISK <- c(0.1, 0.2, 0.4, 0.6)
DrugB_WAIT <- c(0, 0.5, 1, 2)
#Create data frame
df <- data.frame(DrugA_LIFE, DrugA_NEED, DrugA_CERT, DrugA_RISK, DrugA_WAIT, DrugB_LIFE, DrugB_NEED, DrugB_CERT, DrugB_RISK, DrugB_WAIT)
All possible combinations?
expand.gridortidyr::expand_big. We can apply either function to an already-made frame usingdo.call.Unique? Use R's
uniqueordplyr::distinct.Filtering? Use ...
dplyr::filter(or base Rsubset).Data: