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

Weiwei Shi helprhelp at gmail.com
Wed Oct 4 19:18:06 CEST 2006


thanks, Andy and Jacques.
I forgot to convert the result from lapply to data.frame when I tried
lapply last time, :)
I should have done this
data.frame(lapply(x, factor))

On 10/4/06, Liaw, Andy <andy_liaw at merck.com> wrote:
> 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 attachment...{{dropped}}



More information about the R-help mailing list