I have a big database where each row is a segment of text that has been coded with codes belonging to 4 different dimensions. I want to create a new variable to output possible combinations.
Example:
Recipe<-c("ndfkkjd nsakjfbk slgnjkdf", "bffhsbk sbfksdhbk, kbvkbdsk", "asbkdbask", "ouwehowq", "yeueyye fbhfbj")
Origin<-c("Morocco", "Spain", "France", "Spain", "Italy")
Water<-c(1,1,0,1, 1)
Oil<-c(0,0,1,0,0)
Broth<-c(0,0,1,1,1)
Chicken<-c(1,1,0,0,0)
df<-tibble(Recipe=Recipe, Origin=Origin, Broth=Broth, Chicken=Chicken, Oil=Oil, Water=Water)
I want to have a variable that shows the possible combinations of either water or oil, with either broth or chicken. Obviously my database is way larger, and the possible combinations extend to (13 combined with 35), so I really need to do it automatedly. I know that the sum of these variables can never be higher than 2 (ie. not containing more than two ingredients). My desired output should look as follows:
'Broth+Oil'<-c(0,0,1,0,0)
'Broth+Water'<-c(0,0,0,1,1)
'Chicken+Oil'<-c(0,0,0,0,0)
'Chicken+Water'<-c(1,1,0,0,0)
df2<-tibble('Broth+Oil',
'Broth+Water',
'Chicken+Oil',
'Chicken+Water',)
df3<-cbind(df, df2)
so far I just created a vector with all the possible combinations, but I don't really knwo how to evn start thinking about it. Any suggestion would be highly appreciated. Thank you very much!