Skip to content

Fix argument droplevels=FALSE ignored for table1.formula#145

Open
mheinric wants to merge 1 commit intobenjaminrich:masterfrom
mheinric:master
Open

Fix argument droplevels=FALSE ignored for table1.formula#145
mheinric wants to merge 1 commit intobenjaminrich:masterfrom
mheinric:master

Conversation

@mheinric
Copy link

The argument droplevels of the table1.formula function was ignored. For example in the code below:

library(table1)

data <- mtcars
data$cyl <- as.factor(data$cyl)
levels(data$cyl) <- c(levels(data$cyl), "Unused")

print(table1(data = data, x = ~ gear | cyl, droplevels = FALSE))

we would expect the column "Unused" to appear in the resulting table, but this is not the case.

The issue was introduced in c0a31d2 where the line 1516 in table1.R was changed from m2 <- lapply(m2, as.factor) to m2 <- lapply(m2, factorp). The first one preserves the levels of the source columns, while the second does not.

PS: thanks for such a nice package =).

When calling function table1(), the argument droplevels=FALSE had no effect.
The issue was introduced in c0a31d2 where lapply(m2, as.factor) was replaced by lapply(m2, factorp). The first one preserves the levels of the original columns, while the second does not.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant