list all factor levels of a data.frame

前端 未结 6 1223
一整个雨季
一整个雨季 2020-12-28 15:57

with str(data) I get the headof the levels (1-2 values)

fac1: Factor w/ 2  levels ... :
fac2: Factor w/ 5  levels ... :
fac3: Facto         


        
6条回答
  •  悲&欢浪女
    2020-12-28 16:46

    If your problem is specifically to output a list of all levels for a factor, then I have found a simple solution using :

    unique(df$x)

    For instance, for the infamous iris dataset:

    unique(iris$Species)

提交回复
热议问题