s-news
[Top] [All Lists]

RE: [S] Products of pairs

To: suobs@verinet.com, "'Scott.Chasalow@USERS.PV.WAU.NL'" <Scott.Chasalow@USERS.PV.WAU.NL>
Subject: RE: [S] Products of pairs
From: "Gunter, Bert" <bert_gunter@merck.com>
Date: Mon, 30 Mar 1998 11:59:19 -0500
Cc: s-news@wubios.wustl.edu
Sender: owner-s-news@wubios.wustl.edu
Yes, but outer() does the job more simply. Use S-plus built-in functionality
first.


Bert Gunter
Biometrics Research
Merck Research Labs
P.O. Box 2000
Rahway, NJ 07065-0900
732-594-7765

"The business of the statistician is to catalyze the 
scientific learning process."    George E. P. Box

> On Friday, March 27, 1998 at 11:31:22 am CET,
> <suobs@verinet.com> wrote:
> >Is there a simple way to obtain the products of all possible pairs of
> >values that are in a data frame column?
> >
> >Steve Bousquin
> 
> Steve,
> 
> Yes, there is a more efficient way; one which also avoids the dreaded 
> "expressions nested beyond limit" error:
> 
> > z <- 1:10
> > which <- combn2(n = length(z))
> > z[which[,1]] * z[which[,2]]
>  [1]  2  3  4  5  6  7  8  9 10  6  8 10 12 14 16 18 20 12 15 18 21 24 27
> 30 
> 20
> [26] 24 28 32 36 40 30 35 40 45 50 42 48 54 60 56 63 70 72 80 90
> 
> This uses a general strategy that, as often heard on this list, often is 
> preferable in S-PLUS to the use of loops or recursion: first expand the 
> vector by subscripting and then form all the products "at once" using 
> vectorized computation.
> 
        <The rest snipped>
-----------------------------------------------------------------------
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>