Re: [R] two cols in a data frame are the same factor

From: Michael Dewey <>
Date: Wed, 19 Mar 2008 17:57:58 +0000

At 09:11 18/03/2008, Andres Legarra wrote:
>Dear all,
>I have a data set (QTL detection) where I have two cols of factors in
>the data frame that correspond logically (in my model) to the same
>factor. In fact these are haplotype classes.
>Another real-life example would be family gas consumption as a
>function of car company (e.g. Ford, GM, and Honda) (assuming 2 cars by

Unless I completely misunderstand this it looks like you have the dataset in wide format when you really wanted it in long format (to use the terminology of ?reshape). Then you would fit a model allowing for the clustering by family.

>An artificial example follows:
>L3 <- LETTERS[1:3]
>(d <- data.frame( y=rnorm(10), fac=sample(L3, 10,
> lm(y ~ fac+fac1,data=d)
>and I get:
>(Intercept) facB facC fac1B fac1C
> 0.3612 -0.9359 -0.2004 -2.1376 -0.5438
>However, to respect my model, I need to constrain effects in fac and
>fac1 to be the same, i.e. facB=fac1B and facC=fac1C. There are
>logically just 4 unknowns (average,A,B,C).
>With continuous covariates one might do y ~ I(cov1+cov2), but this is
>not the case.
>Is there any trick to do that?
>Andres Legarra
>Toulouse, France

Michael Dewey mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Wed 19 Mar 2008 - 18:01:04 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 Thu 20 Mar 2008 - 08:30:22 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive