[R] fast code

Warnes, Gregory R gregory_r_warnes at groton.pfizer.com
Fri Dec 6 20:00:03 CET 2002


Perhaps this will do the trick:

> tmp <- data.frame(x1=c(3,4,6.5,20,35), x2=c(3.1,4.2,5,24,38) )
> attach(tmp)
> 
> tmp$x3 <- sapply( x2, function(val) max(x1[x1<val]) )
> 
> tmp
    x1   x2 x3
1  3.0  3.1  3
2  4.0  4.2  4
3  6.5  5.0  4
4 20.0 24.0 20
5 35.0 38.0 35

-G

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


LEGAL NOTICE\ Unless expressly stated otherwise, this message is ... [[dropped]]




More information about the R-help mailing list