I'm starting out in R, and pretty sure this is achievable via one of the apply functions. 
I have two differently sized vectors, a <- c('A', 'B', 'C') and b <- c('A', 'B', 'C', 'D', 'E'). 
I want to compare the values of a and b, and where they match, put a one in a matrix, or zero if they do not match. So, using the above, something that looks like: 
    A   B   C   D   E
A   1   0   0   0   0
B   0   1   0   0   0
C   0   0   1   0   0
I can do this via a for loop easy enough, but is there a more R-esque way of completing the above?
(Apologies, as I recognise this is probably a duplicate question, I'm just not sure what terms I should be searching for)
                        
Just try:
If you want row and column names:
EDIT
Just a funnier one: