[R] unique sets of factors
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: [EMAIL PROTECTED] http://hjmuller.bio.uci.edu/~labhome/ __ R-help@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.
Re: [R] unique sets of factors
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 [EMAIL PROTECTED] 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: [EMAIL PROTECTED] http://hjmuller.bio.uci.edu/~labhome/ __ R-help@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. __ R-help@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.
Re: [R] unique sets of factors
Or since that messes up the values: u - unique(t(apply(DF, 1, function(x) as.numeric(factor(x, levels = unique(x)) DF[rownames(u), ] On 10/19/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: 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 [EMAIL PROTECTED] 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: [EMAIL PROTECTED] http://hjmuller.bio.uci.edu/~labhome/ __ R-help@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. __ R-help@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.