I tried merge() but it doesn't make any sense here, and I also tried to melt() the orginal data that table1 and table2 are created from to re-created a "combined" table from one step further back from this but couldn't get it to form the right table.

If that would be an easier solution, here is the starting point that table1 and table2 are created from and also the create.table() function I wrote to create them:
create.table <- function(a,b){
obs <- unique(c(a,b))
squ <- matrix(rep(0,length(obs)^2),ncol=length(obs))
for(i in 1:length(obs)){
for(j in 1:length(obs)){
squ[i,j] <- sum((a==obs[i])*(b==obs[j]), na.rm=TRUE)
}
}
squ
}

#This is what my real data looks like
#It may be easier to reformat this df to a format that could then use my create.table() function to get to the combined table endpoint?
mydf <- as.data.frame(cbind(sampleid,Q1before, Q1after, Q2before, Q2after))
create.table(mydf$Q1before, mydf$Q1after)
create.table(mydf$Q2before, mydf$Q2after)

I hope at least some of this makes sense. Thank you for your input, you guys are always the best!

> [,1] [,2] [,3] [,4]
>newrow1 1 1 0 0
>newrow2 1 2 0 0
>newrow3 0 0 0 1
>newrow4 0 0 0 4
>
>I tried merge() but it
doesn't make any sense here, and I also tried to melt() the orginal data
that table1 and table2 are created from to re-created >a "combined"
table from one step further back from this but couldn't get it to form
the right table.
>
>If that would be an easier solution, here is the starting point
that table1 and table2 are created from and also the create.table()
function I wrote to >create them:
>
>create.table <- function(a,b){
> obs <- unique(c(a,b))
> squ <- matrix(rep(0,length(obs)^2),ncol=length(obs))
> for(i in 1:length(obs)){
> for(j in 1:length(obs)){
> squ[i,j] <- sum((a==obs[i])*(b==obs[j]), na.rm=TRUE)
> }
> }
> squ

use my create.table() function to get to the combined table endpoint?
>mydf <- as.data.frame(cbind(sampleid,Q1before, Q1after, Q2before, Q2after))
>create.table(mydf$Q1before, mydf$Q1after)
>create.table(mydf$Q2before, mydf$Q2after)
>
>I hope at least some of this makes sense. Thank you for your input, you guys are always the best!