Lets say I have a factor level that I need to delete for the analysis for whatever reasons. I make a subset, but the factor level still exists.
Luckily, there is an argument in sjt.xtab that specifies:
drop.empty: Logical, if TRUE and the variable’s values are labeled, values that have no observations are still printed in the table (with frequency 0). If FALSE, values / factor levels with no occurrence in the data are omitted from the output.
Source: https://cran.r-project.org/web/packages/sjPlot/sjPlot.pdf
But it isn't working. Here is a minimal working example:
color <- factor(c("blue", "yellow", "red", "red", "blue"))
object <- factor(c("table", "chair", "table", "chair", "chair"))
df <- data.frame(color, object)
sjPlot::sjt.xtab(df$color, df$object) # We decide to delete "yellow" case(s)
df <- subset(df, color == "red" | color == "blue")
sjPlot::sjt.xtab(df$color, df$object, drop.empty = FALSE)
Does anybody knows why is it not working?
I know we could use the droplevels() function but I would like to know if I am doing something wrong with the drop.empty argument
Best,