Skip to content

Instantly share code, notes, and snippets.

@jonesor
Created July 3, 2014 11:37
Show Gist options
  • Save jonesor/9226171af14873ad332d to your computer and use it in GitHub Desktop.
Save jonesor/9226171af14873ad332d to your computer and use it in GitHub Desktop.
Remove unused factor levels in a data frame
dropall <- function(x){
isFac = NULL
for (i in 1:dim(x)[2]){isFac[i] = is.factor(x[ , i])}
for (i in 1:length(isFac)){
x[, i] = x[, i][ , drop = TRUE]
}
return(x)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment