> x1 <- matrix(rnorm(225),nrow=25,ncol=9)
> xc3 <- c(3:9,4:9,5:9,6:9,7:9,8:9,9,
+ 4:9,5:9,6:9,7:9,8:9,9,
+ 5:9,6:9,7:9,8:9,9,
+ 6:9,7:9,8:9,9,
+ 7:9,8:9,9,
+ 8:9,9,
+ 9)
> xc2 <- c(rep(2,7),rep(3,6),rep(4,5),rep(5,4),rep(6,3),rep(7,2),8,
+ rep(3,6),rep(4,5),rep(5,4),rep(6,3),rep(7,2),8,
+ rep(4,5),rep(5,4),rep(6,3),rep(7,2),8,
+ rep(5,4),rep(6,3),rep(7,2),8,
+ rep(6,3),rep(7,2),8,
+ rep(7,2),8,
+ 8)
> xc1 <- c(rep(1,28),rep(2,21),rep(3,15),rep(4,10),rep(5,6),rep(6,3),7)
> x2 <- numeric(length=84)
> xt <- cbind(xc1,xc2,xc3)
> for(i in 1:84)x2[i] <- sum(x1[,xt[i,1:3]])
Now the xt matrix has the list of the possible combinations. You
end up with the x2 vector with all of the sums. There are 84 possible
combinations; i.e., the combination of 9 items taken 3 at a time.
I hope this helps!
Sincerely,
Erin Hodgess
Assistant Professor
Dept. of Computer and Mathematical Sciences
University of Houston -- Downtown
e-mail: hodgess@uhdux2.dt.uh.edu
From: "David H. Gleaves" <dhg@psyc.tamu.edu>
Organization: tamu/psycdept
To: s-news@wubios.wustl.edu
Date: Wed, 11 Feb 1998 19:21:34 CST6CDT
Subject: [S] help transforming a matrix
In-Reply-To: <199802110735.BAA03199@wubios.wustl.edu>
X-Mailer: Pegasus Mail for Windows (v2.52)
Message-Id: <1F6D01F1A23@psyc.tamu.edu>
Sender: owner-s-news@wubios.wustl.edu
Status: R
I would be extremely greatful for some help with this problem.
I have a matrix with nine variables (columns). I need to output a
new matrix with three variables, each of which being the sum of three
of the nine variables (e.g. v1+v2+v3, v4+v5+v6, v7+v8+v9). Then, I
need to do this for all possible combinations of three variables.
These could either be output into one three dimensional array or
separate two dimensional matrices for each of the possible
combinations.
I'm using S-Plus 3.3 with Windows 3.2
As I said, I would greatly appreciate any help with this, and please
send responses to my personal e-mail rather than the list.
Thanks
David H. Gleaves, Ph.D.
Assistant Professor, Department of Psychology
Texas A&M University, College Station, TX 77843-4235
dhg@tamu.edu, http://acs.tamu.edu/~Gleaves/
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news