Re: [R] Catenating factors.

From: Mike Lawrence <Mike.Lawrence_at_dal.ca>
Date: Wed, 23 May 2007 08:40:10 -0300

It may be poor form, but whenever I deal with factors in this way I find as.character and as.numeric useful

ex.

#if your factor levels are letters
z=factor(unique(c(as.character(x),as.character(y))))

#if your factor levels are numbers
z=factor(unique(c(as.numeric(as.character(x)),as.numeric(as.character (y)))))

On 22-May-07, at 11:56 PM, Marc Schwartz wrote:

> On Wed, 2007-05-23 at 13:38 +1200, Rolf Turner wrote:
>>
>> I was recently asked by one of new colleagues how to combine, or
>> catentate,
>> or concatentate two factors. If x and y are factors, doing c(x,y)
>> appears
>> to coerce x and y to numeric mode before catenating them. So what
>> does one
>> do if one wants the result to be a factor whose levels are the
>> union of the
>> levels of x and y? I vaguely recall seeing this discussed in r-
>> help, but I
>> can't find anything on it there, nor in the FAQ.
>>
>> Am I missing something obvious?
>
> Rolf,
>
> I think that this thread from last November on R-devel may be helpful:
>
> http://tolstoy.newcastle.edu.au/R/e2/devel/06/11/1130.html
>
> HTH,
>
> Marc Schwartz
>
> ______________________________________________
> 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.

--
Mike Lawrence
Graduate Student, Dalhousie University Department of Psychology
http://myweb.dal.ca/mc973993

"The road to wisdom? Well, it's plain and simple to express:
Err and err and err again, but less and less and less."
- Piet Hein

______________________________________________
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.
Received on Wed 23 May 2007 - 12:00:58 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 23 May 2007 - 12:31:24 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.