3.4 Making tables
A nice thing about numeric and factor variables is we can use the table command to see how many observations in our data fall into each category or numerical value.
## Example: how many black vs. white sounding resumes
table(resume$race)##
## black white
## 2435 2435
As mentioned, factor variables have levels:
levels(resume$race)## [1] "black" "white"
3.4.1 Crosstabulation
We can also use the table command to show a crosstabulation: a table that displays the frequency of observations across two variables.
## Example: how many black vs. white sounding resumes by call backs
## We can label the two dimensions of the table with the =
table(calledback = resume$call, race = resume$race)## race
## calledback black white
## 0 2278 2200
## 1 157 235
Sometimes we will want to show the proportion instead of the frequency using prop.table
## Example: proportion black vs. white sounding resumes by call backs
## Convert to proportion
prop.table(table(calledback = resume$call, race = resume$race), margin = 2) # 1 for row sum, 2 for col## race
## calledback black white
## 0 0.93552361 0.90349076
## 1 0.06447639 0.09650924
How can we interpret this crosstabulation? It should let us see the causal effect– the callback rate for each group