How can I drop unused levels from a data frame?

后端 未结 3 1560
执念已碎
执念已碎 2020-12-04 15:50

Given the following mock data:

set.seed(123)
x <- data.frame(let = sample(letters[1:5], 100, replace = T), 
                num = sample(1:10, 100, replac         


        
3条回答
  •  广开言路
    2020-12-04 16:00

    Just do y$let <- factor(y$let). Running factor on an existing factor variable will reset the levels to only those that are present.

提交回复
热议问题