[R] What is the correct way to merge factors?

Liaw, Andy andy_liaw at merck.com
Thu Feb 5 21:22:45 CET 2004


You can do:

  factor(c(as.character(l1), as.character(l2)))

HTH,
Andy

> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch 
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Svetlana Eden
> Sent: Thursday, February 05, 2004 2:51 PM
> To: r-help at stat.math.ethz.ch
> Subject: Re: [R] What is the correct way to merge factors?
> 
> 
> I have two factors l1, l2, and I'd like to merge them.
> Function c() does not give me the result I want:
> 
> > l1 = factor(c('a', 'b'))
> > l2 = factor(c('c', 'd'))
> > lMerge = c(l1, l2)
> > lMerge
> [1] 1 2 1 2
> >
> 
> I'd like to merge l1 and l2 and to get lMerge 
> ----------------------------------------------
> 
> [1] a b c d
> Levels: a b c d
> 
> instead of 
> ----------
> 
> [1] 1 2 1 2
> >
> 
> How should I do that?
> ---------------------
> 
> -- 
> Svetlana Eden        Biostatistician II            School of Medicine
>                      Department of Biostatistics   Vanderbilt 
> University
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html
> 
> 


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




More information about the R-help mailing list