You need to convert your vectors to factor
s, with each vector having all the levels
you want to include in your output.
levs <- sort(union(data.1, data.2))
table(factor(data.1, levs), factor(data.2, levs))
#
# 1 2 3 4
# 1 1 0 2 0
# 2 1 0 1 1
# 3 0 0 0 0
# 4 1 0 0 0