[R] "Glueing" factors together

(Ted Harding) Ted.Harding at nessie.mcc.ac.uk
Tue Jun 15 10:54:18 CEST 2004


On 15-Jun-04 Peter Dalgaard wrote:
> (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk> writes:
> 
> ...
>> then I'd like to end up with a single factor with levels
>> 
>>   A0B0, A0B1, A0B2, A1B0, A1B1, A1B2
>> 
>> according to all the combinations which actually occur in the
>> data (e.g. if (A1,B2) did not occur in the data, then A1B2 would
>> not be a level in the resulting "glued" factor).
>> 
>> I can see clumsy and tedious ways involving manipulating strings,
>> paste(), etc.; but I'm sure it must be possible more elegantly.
> 
> You mean like interaction()?

Thanks! Yes, interaction(A,B,drop=TRUE) does it.
Best wishes,
Ted.


--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk>
Fax-to-email: +44 (0)870 167 1972
Date: 15-Jun-04                                       Time: 09:54:18
------------------------------ XFMail ------------------------------




More information about the R-help mailing list