I have a data frame, which looks something like this:
CASENO Var1 Var2 Resp1 Resp2
1 1 0 1 1
2 0 0 0 0
3 1 1 1 1
4 1 1 0 1
5 1 0 1 0
There are over 400 variables in the dataset. This is just an example. I need to create a simple frequency matrix in R (excluding the case numbers), but the table
function doesn't work. Specifically, I'm looking to cross-tabulate a portion of the columns to create a two-mode matrix of frequencies. The table should look like this:
Var1 Var2
Resp1 3 1
Resp2 3 2
In Stata, the command is:
gen var = 1 if Var1==1
replace var= 2 if Var2==1
gen resp = 1 if Resp1==1
replace resp = 2 if Resp2==1
tab var resp
m <- as.matrix(d)
since the greps will never match the first column anyways. – Germin