HI,
You can also try this:
set.seed(1)
dat1<-data.frame(col1=factor(sample(1:25,10,replace=TRUE)),col2=sample(letters[1:10],10,replace=TRUE),col3=factor(rep(1:5,each=2)))
sapply(lapply(mapply(c,lapply(names(sapply(dat1,levels)),function(x) x),sapply(dat1,levels)),function(x) paste(x[1],":",paste(x[-1],collapse=" "))),print)
#[1] "col1 : 2 6 7 10 15 16 17 23 24"
#[1] "col2 : b c d e g h j"
#[1] "col3 : 1 2 3 4 5"
#[1] "col1 : 2 6 7 10 15 16 17 23 24" "col2 : b c d e g h j"?????????
#[3] "col3 : 1 2 3 4 5"??
A.K. ??
----- Original Message -----
From: "Lopez, Dan" <lopez235 at llnl.gov>
To: "R help (r-help at r-project.org)" <r-help at r-project.org>
Cc:
Sent: Tuesday, October 16, 2012 11:19 AM
Subject: [R] List of Levels for all Factor variables
Hi,
I want to get a clean succinct list of all levels for all my factor variables.
I have a dataframe that's something like #1 below. This is just an example subset of my data and my actual dataset has 70 variables. I know how to narrow down my list of variables to just my factor variables by using #2 below (thanks to Bert Gunter). I can also get list of all levels for all my factor variables using #3 below. But I what I want to find out is if there is a way to get this list in a similar fashion to what the str function returns: without all the extra spacing and carriage returns. That's what I mean by "clean succinct list".
BTW I also tried playing around with several of the parameters for the str function itself but could not find a way to accomplish what I want to accomplish.
1.? ? ? DATAFRAME