[R] apply( )

Gabor Grothendieck ggrothendieck at gmail.com
Thu May 10 20:09:10 CEST 2007

```Sorry, you wanted or, not and.

with(foo, pmax(x < y, x > z))

with(foo, as.numeric(x < y | x > z))

with(foo, 1*(x < y | x > z))

On 5/10/07, Gabor Grothendieck <ggrothendieck at gmail.com> wrote:
> or
>
>   with(foo, (x < y) * (x > z))
>
> On 5/10/07, jim holtman <jholtman at gmail.com> wrote:
> > You don't need apply.  Just do
> >
> > foo\$result <- ifelse((foo\$x < foo\$y) | (foo\$x > foo\$z), 1, 0)
> >
> > On 5/10/07, Greg Tarpinian <sasprog474 at yahoo.com> wrote:
> > > I have a question that must have a simple answer (but eludes me).
> > > I need a row-by-row logical comparison across three numeric variables
> > > in
> > > a data frame: foo\$x, foo\$y, foo\$z.  The logic is
> > >
> > >   if( x < y || x > z ) 1 else 0
> > >
> > > for a particular row.
> > >
> > > It is simple and very inefficient to use for(i in 1:length(foo\$x)){ }
> > > loops.  How can I accomplish this using sappy( ) / lapply( ) / apply( )
> > > or some other more efficient method?
> > >
> > > Thank you in advance,
> > >
> > >    Greg
> > >
> > > ______________________________________________
> > > R-help at stat.math.ethz.ch mailing list
> > > https://stat.ethz.ch/mailman/listinfo/r-help
> > > and provide commented, minimal, self-contained, reproducible code.
> > >
> >
> >
> > --
> > Jim Holtman
> > Cincinnati, OH
> > +1 513 646 9390
> >
> > What is the problem you are trying to solve?
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help