search for: dropit

Displaying 1 result from an estimated 1 matches for "dropit".

Did you mean: dropin
2009 Nov 10
3
drop unused levels in subset.data.frame
...13 $ y: Factor w/ 3 levels "A","B","C": 1 1 1 1 1 The subset still retains all the unused factor levels. I wonder how people usually get rid of all unused levels in a data.frame after subsetting? I came up with this but I may have missed a better built-in solution, dropit <- function (d, columns = names(d), ...) { d[columns] = lapply(d[columns], "[", drop=TRUE, ...) d } str(dropit(s)) 'data.frame': 5 obs. of 2 variables: $ x: Factor w/ 5 levels "a","d","g","j",..: 1 2 3 4 5 $ y: Factor w/ 1 lev...