I am running some demographic data in R. I have created new variables which show what responses represent what demographic. Here is the example of the code I am running
data$race <- NULL
data$race [data$q1 == 1] <- "White"
data$race [data$q1 == 2] <- "Black / African American"
data$race [data$q1 == 3] <- "Hispanic / Latino"
data$race [data$q1 == 4] <- "Asian"
...
The problem I am encountering is that not every demographic appears in my data set. As such, when I run the table, some demographics don't show up.
table (data$race)
White Black / African American Hispanic / Latino
100 100 25
I want to create a table that lists the empty demographics as zero.
table (data$race)
White Black / African American Hispanic / Latino Asian
100 100 25 0
I am not sure if there is an option in table to do this. Does anyone know of a way to code this? I tried exclude = FALSE, but that just creates an column. Is there a different option I can use?