Here is my data:
sub <- paste ("s", 1:6, sep = "")
mark1a <- c("A", "A", "B", "d1", "A", 2)
mark1b <- c("A", "B", "d1", 2, "d1", "A")
myd <- data.frame (sub, mark1a, mark1b)
myd
sub mark1a mark1b
1 s1 A A
2 s2 A B
3 s3 B d1
4 s4 d1 2
5 s5 A d1
6 s6 2 A
I want create a design matrix of the pair of variables (columns) – mark1a and mark1b. A design matrix will consists of length (unique (c(mark1a, mark1b))) for each unique (c(mark1a, mark1b). then 1 or 2 based on if the particular number is present once or twice in the columns and else 0. The following is expected output (not a figure):

I could understand how this can be done:
You could try something like this: