s-news
[Top] [All Lists]

[S] trying to avoid looping

To: "'s-news@wubios.wustl.edu'" <s-news@wubios.wustl.edu>
Subject: [S] trying to avoid looping
From: Pamela Goodman <pgoodman@nwifc.wa.gov>
Date: Fri, 15 Sep 2000 12:01:33 -0700
Sender: owner-s-news@wubios.wustl.edu
Greetings Everyone,

I need to do a computation that requires all unique products of two columns
of a matrix (or data frame, I'm not picky), including the multiplication of
the columns with themselves. 

That is, for a 2x3 matrix:

test <- matrix(1:6, nrow=2)

I need: 

m1<-test[,1]*test[,1]
m2<-test[,1]*test[,2]
m3<-test[,1]*test[,3]
m4<-test[,2]*test[,2]
m5<-test[,2]*test[,3]
m6<-test[,3]*test[,3]

and products such as:

m7<-test[,3]*test[,2] 

are redundant.

The problem is that the data sets will dictate the number of columns, and
each data set will likely be different. I need to have the code generate the
correct number of products for the general case.

Because this "all-possible-2-column-products" computation is going to be
done at each iteration, until convergence, I would like the above done
without looping. 

I will compile the answers I receive and post them to the group.

Thanks in advance,

Pam
    

###################################
Pam Goodman
Biometrician
Northwest Indian Fisheries Commission
6730 Martin Way E
Olympia, WA 98516-5540
Phone: (360)438-1181 ext 380
Fax: (360)753-8659
http://www.nwifc.wa.gov/
###################################
-----------------------------------------------------------------------
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

<Prev in Thread] Current Thread [Next in Thread>
  • [S] trying to avoid looping, Pamela Goodman <=