[R] how to convert all columns of a data frame into factors

Liaw, Andy andy_liaw at merck.com
Wed Oct 4 17:49:31 CEST 2006


Alternatively:

x[] <- lapply(x, factor)

Recall that a data frame is a list, so lapply() is a natural choice.

Andy 

From: Gabor Grothendieck
> 
> Try this:
> 
> replace(BOD, TRUE, lapply(BOD, factor))
> 
> 
> On 10/4/06, Weiwei Shi <helprhelp at gmail.com> wrote:
> > Hi,
> >
> > I use "apply"
> > apply(x, 2, factor)
> >
> > but it does not work. please help. thanks.
> >
> > --
> > Weiwei Shi, Ph.D
> > Research Scientist
> > GeneGO, Inc.
> >
> > "Did you always know?"
> > "No, I did not. But I believed..."
> > ---Matrix III
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide 
> > http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 
> 


------------------------------------------------------------------------------
Notice:  This e-mail message, together with any attachments,...{{dropped}}



More information about the R-help mailing list