Hello,
There are two things I am hoping to get right:
- I have the following data below. I want to be able to cut invalid
selection
columns. Invalid selection columns are those that contain both "a -> b" and "b -> a" as an example, i.e. if the source = target and the target = source for two path combinations then it shouldn't be valid as it can only be directed into a single direction between those nodes. See example data below:
df1 <- data.frame(
stringsAsFactors = FALSE,
source = c("a", "b", "c", "d", "e", "c", "a", "e", "a"),
target = c("b", "c", "d", "e", "a", "b", "d", "d", "e"),
selection1 = c(1, 0, 1, 0, 0, 1, 1, 0, 0),
selection2 = c(1, 1, 0, 0, 1, 1, 0, 0, 1),
selection3 = c(1, 1, 1, 1, 1, 0, 0, 0, 0)
)
- Then I also have a second problem which I believe to be more complicated and I am hoping there is a package for this. I want to exclude selections that have contradictory self reference i.e. a->b b->c c->a. This combination is essentially a triangle and our start and end point is the same node. This condition shouldn't be true for combinations. So a -> b and c-> a would be fine and b->c with either path 1 or 3 but not the combination of all three. These toy problems are relatively simple but I would want them to work for complicated dataframes too.
df2 <- data.frame(
stringsAsFactors = FALSE,
source = c("a", "b", "c", "a", "b"),
target = c("b", "c", "a", "d", "d"),
seection1 = c(1, 1, 1, 1, 0),
seection2 = c(1, 0, 1, 0, 0),
seection3 = c(1, 0, 0, 0, 1)
)
Any help would be massively appreciated!