Skip to content
Prev 308198 / 398503 Next

List of Levels for all Factor variables

Given dat1, does this work?
is.factor)],
+      nlevels), Names=sapply(x[sapply(x, is.factor)], 
+      function(y) paste0(levels(y), collapse=", "))), right=FALSE)
+ }
Lvls Names                          
col1 9    2, 6, 7, 10, 15, 16, 17, 23, 24
col2 7    b, c, d, e, g, h, j            
col3 5    1, 2, 3, 4, 5                  

It automatically extracts the columns that are factors so it should work on
your original data.frame.

----------------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352