[R] fast code

Huntsinger, Reid reid_huntsinger at merck.com
Fri Dec 6 22:27:03 CET 2002


You could use "cut" as follows:

i <- cut(x2,c(x1,Inf),labels=FALSE)

to get the intervals of x1 into which the
entries of x2 fall, then

x3 <- x1[i]

to get the left endpoints. This will give NA for elements of
x2 smaller than any element of x1, which I think you want. 
You may want to play with the options to "cut" to get the
right behavior for exact equality between elements of x1 and x2.

Note x2 need not be sorted. I don't see a way to take advantage
of sorted x2 without explicit looping.

Reid Huntsinger



-----Original Message-----
From: Pantelis Andreou [mailto:pan at mathstat.dal.ca]
Sent: Friday, December 06, 2002 1:21 PM
To: Janusz Kawczak
Cc: r-help at stat.math.ethz.ch
Subject: Re: [R] fast code


Hello again,
here is an example
x1      x2      x3
3       3.1     3
4       4.2     4
6.5     5	4
20      24	20
35      38	35


On Fri, 6 Dec 2002, Janusz Kawczak wrote:

> Example would help!
> 
> On Fri, 6 Dec 2002, Pantelis Andreou wrote:
> 
> > Date: Fri, 6 Dec 2002 14:09:22 -0400 (AST)
> > From: Pantelis Andreou <pan at mathstat.dal.ca>
> > To: r-help at stat.math.ethz.ch
> > Subject: [R] fast code
> >
> > Hello again,
> > I think I made a mistake discribing the problem.
> > I have two column vectors x1 and x2 both in increasing order.
> > I need a column vector x3 such that
> > the jth entry of x3 is the maximum ith entry x1 which is smaller
> > than the jth entry of x2.
> > Regards,
> > Pantelis
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > http://www.stat.math.ethz.ch/mailman/listinfo/r-help
> >
> 
>

______________________________________________
R-help at stat.math.ethz.ch mailing list
http://www.stat.math.ethz.ch/mailman/listinfo/r-help


------------------------------------------------------------------------------
Notice:  This e-mail message, together with any attachments, contains information of Merck & Co., Inc. (Whitehouse Station, New Jersey, USA) that may be confidential, proprietary copyrighted and/or legally privileged, and is intended solely for the use of the individual or entity named in this message.  If you are not the intended recipient, and have received this message in error, please immediately return this by e-mail and then delete it.




More information about the R-help mailing list