[S] a and b of diff. length

Erin Hodgess (hodgess@uhdux2.dt.uh.edu)
Tue, 28 Apr 1998 15:28:18 -0500


Dear Robert:

I am probably making your question overly simple but here is
an example that I hope will help:
> a1 <- rnorm(20)
> b1 <- rnorm(30)
> a1
[1] 0.9895330 0.2516856 0.4558824 -0.8722180 2.3240117 1.0401466
[7] 0.6311775 -1.0208775 0.8737637 -0.4142970 0.2662127 0.9780478
[13] -0.3701643 -0.7251656 1.9583886 -1.2558284 0.3632041 -0.6491927
[19] 0.4395929 0.6954919

> b1
[1] -0.6982503297 2.4679099042 2.0054586151 1.5850197876 0.5416405446
[6] -0.3376437488 1.0275195711 0.0135072055 0.6035765059 -0.0238450333
[11] 0.8255426050 0.3549822410 -0.4993666028 -0.0009746859 -0.6969294057
[16] -1.7040940337 -0.1465237853 0.1096017305 1.7887338080 -1.1403967305
[21] -2.0645898271 -1.1426061685 0.4127305808 1.2834581573 0.1613587418
[26] 0.5164874860 -0.5971750556 -2.2070765576 -0.3385439919 0.6439100724

> a1 + (a1*b1[1:length(a1)])
[1] 0.29859125 0.87282297 1.37013574 -2.25470077 3.58279072 0.68894762
[7] 1.27972477 -1.03466665 1.40114689 -0.40441809 0.48598259 1.32523739
[13] -0.18531660 -0.72445881 0.59352999 0.88422130 0.30998603 -0.72034532
[19] 1.22590748 -0.09764479
>

For what it's worth, there it is.
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: Robert Lyles <rlyles@sph.jhu.edu>
Subject: [S] question
X-Sender: rlyles@statepi
To: s-news@utstat.toronto.edu
Cc: rlyles@sph.jhu.edu
Message-Id: <Pine.SOL.3.96.980428145040.29019A-100000@statepi>
Mime-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
Sender: owner-s-news@wubios.wustl.edu
Status: R

I have a question on a particular computation in Splus:

Suppose "a" is a sequence of length n, and "b" is another sequence of
length m, where m<n. You would like to return a sequence of length n,
whose ith element (i=1,...,n) is the product over j=1,...,m of a function
like Phi(a_i + a_i*b_j). Here, Phi is the standard normal cdf ("pnorm"),
and i and j are being used to index the elements of "a" and "b",
respectively.

My question for more experienced Splus users is, is there an efficient way
to do this, somehow taking advantage of the default matrix arithmetic
rules (i.e., if possible without using a "for" loop, etc.)?

Thanks very much for considering this question.

-----------------------------------------------------------------------
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