[R] unique sets of factors
Gabor Grothendieck
ggrothendieck at gmail.com
Fri Oct 20 01:15:36 CEST 2006
If DF is a data frame containing the rows then:
unique(t(apply(DF, 1, function(x) as.numeric(factor(x, levels = unique(x))))))
On 10/19/06, Tony Long <tdlong at uci.edu> wrote:
> All:
>
> I have a matrix, X, with a LARGE number of rows. Consider the
> following three rows of that matrix:
>
> 1 1 1 1 2 2 3 3
> 1 1 1 1 3 3 2 2
> 3 3 2 2 1 1 1 1
>
> I wish to fit many one-way ANOVAs to some response variable using
> each row as a set of factors. For example, for each row above I will
> do something like anova(lm(Y~as.factor(X[1,]))). My problem is that
> in the above example, I do not want to fit models for both rows 1 and
> 2 as they are essentially duplicates in terms of the ANOVA model.
> Clearly row 3, although it has the same number of 1's, 2's, and 3's,
> is a different model.
>
> Is there some computationally efficient way to remove such "factor
> duplicates" from my large matrix? I have been banging my head
> against the wall all morning.
>
> Thanks!!
>
> Tony
> --
> ###########################
>
> Tony Long
>
> Ecology and Evolutionary Biology
> Steinhaus Hall
> University of California at Irvine
> Irvine, CA
> 92697-2525
>
> Tel: (949) 824-2562 (office)
> Tel: (949) 824-5994 (lab)
> Fax: (949) 824-2181
>
> email: tdlong at uci.edu
> http://hjmuller.bio.uci.edu/~labhome/
>
> ______________________________________________
> 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.
>
More information about the R-help
mailing list