Re: [R] apply( )

From: Petr PIKAL <petr.pikal_at_precheza.cz>
Date: Fri, 11 May 2007 11:00:06 +0200


Hi
r-help-bounces_at_stat.math.ethz.ch napsal dne 10.05.2007 17:59:22:

> or
>
> with(foo, (x < y) * (x > z))

Should not it be

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

Regards
Petr

>
> On 5/10/07, jim holtman <jholtman@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
> > > PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> > > 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
> > PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
>
> ______________________________________________
> R-help_at_stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide

http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



R-help_at_stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Fri 11 May 2007 - 09:05:53 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 11 May 2007 - 09:31:28 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.