I am trying to use table function in r to create a contingency table. But instead of a contingency table, I got values (instead of table), list of two.
My data has 15000 observations and 2 variables. The data looks like this:
**Field.Label** |**Form.Name**
------------------------------------|---------------
Applicant Name |F1
------------------------------------|---------------
Phone |F1
------------------------------------|---------------
Address |F1
------------------------------------|---------------
Phone |F2
------------------------------------|---------------
Address |F2
------------------------------------|---------------
Title |F2
------------------------------------|---------------
Phone |F3
------------------------------------|---------------
... |...
I used following code:
CTable<-table(mydata$Field.Label, mydata$Form.Name)
CTable<-as.data.frame(CTable)
View(CTable)
And got result like this with 1,665,495 entries (Field.Label has 8,541 levels, and Form.Name has 195 levels. 8,541 * 195 = 1,665,495):
** Field.Label** |** Form.Name** |**Freq**
------------------------------------|---------------|-----------
Applicant Name |F1 |1
------------------------------------|---------------|-----------
Phone |F1 |1
------------------------------------|---------------|-----------
Address |F1 |1
------------------------------------|---------------|-----------
Title |F1 |0
------------------------------------|---------------|-----------
Applicant Name |F2 |0
------------------------------------|---------------|-----------
Phone |F2 |1
------------------------------------|---------------|-----------
Address |F2 |1
------------------------------------|---------------|-----------
Title |F2 |1
------------------------------------|---------------|-----------
Applicant Name |F3 |0
------------------------------------|---------------|-----------
Phone |F3 |1
------------------------------------|---------------|-----------
Address |F3 |0
------------------------------------|---------------|-----------
Title |F3 |0
------------------------------------|---------------|-----------
... |...
How can I get the result of contingency table like the following?
|**F1** |**F2** |**F3** |
------------------------------------|-------|-------|-------|
Applicant Name | 1 |0 |0 |
------------------------------------|-------|-------|-------|
Phone | 1 |1 |1 |
------------------------------------|-------|-------|-------|
Address | 1 |1 |0 |
------------------------------------|-------|-------|-------|
Title | 0 |1 |0 |
------------------------------------|-------|-------|-------|
Thanks!