My point of departure is the whigs data from the ggraph package. It contains an incidence matrix.
Now, for each combination of columns/variables, I'd like to know if all the columns are 1 or not, and create a new column for that combination with a 1 if indeed all the columns are 1 or a 0 if not.
The whigs data is just an example: I'm looking for a vectorized method that can be used regardless of the number of columns/combinations.
Using dplyr, I can use across()
in the mutate()
function to create multiple new columns, but I can't figure out how to create those columns on the basis of the various combinations of columns.
Also using dplyr, I can use c_across()
in the mutate()
function, in tandem with the rowwise()
function, to create a single new column based on the values in multiple columns.
Maybe these two can be combined somehow?