Skip to content
Prev 303997 / 398506 Next

Reshaping dataframes

On Aug 23, 2012, at 2:02 AM, Ingmar Schuster wrote:

            
Not sure what you mean by " _while_ binding dataframes" but the  
original question seems answered by this sentence from the help file  
for factor:

"For a numeric x, set exclude=NULL to make NA an extra level (prints  
as <NA>); by default, this is the last level."

fac <- factor(fac, exclude=NULL) # would skip all that `is.na()`,  
`level=` gymnastics


If you want to loop over factor dataframe columns:

facidx <-  sapply(d, is.factor)
d[ ,facidx ] <- lapply( d[ , facidx ], factor, exclude=NULL)

I see no parameters to data.frame or read.table that would allow  
specifying different than the default behavior for factor().