Dropping factors which levels have observations smaller than a specific value-R

后端 未结 4 687
臣服心动
臣服心动 2021-01-16 19:49

Let I have such data frame(df1) with factors:

factor1  factor2  factor3
-------  -------  -------
d        a         x
d        a         x
b        a                


        
4条回答
  •  悲&欢浪女
    2021-01-16 20:38

    is that what you want?

    df <- data.frame(col1=rep(letters[1:4], each=3),
                     col2=rep(letters[1:2], each=6),
                     col3=rep(letters[1:3], each=4))
    
    ddf[, sapply(df, function(x) min(nlevels(x)) > 2)]
    

提交回复
热议问题