Last active
July 18, 2026 20:21
-
-
Save jonesor/9226171af14873ad332d to your computer and use it in GitHub Desktop.
Remove unused factor levels in a data frame
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Remove unused factor levels in a data frame. | |
| # Base R's droplevels() does exactly this (drops unused levels from every factor | |
| # column) and is the recommended replacement for the original hand-rolled loop, | |
| # which errored on non-factor columns. | |
| dropall <- function(x){ | |
| droplevels(x) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment