[R] apply problem
ripley@stats.ox.ac.uk
ripley at stats.ox.ac.uk
Sun Mar 17 15:48:35 CET 2002
On Sun, 17 Mar 2002 ggrothendieck at yifan.net wrote:
>
> > > > apply(iris3,1,function(x)identical(x,iris3[1,]))
> > > 1 2 3
> > > FALSE FALSE FALSE
> > >
> > > What's wrong here?
> >
> > iris3 is not an array, so it it coerced to one via as.matrix
> [...]
> > and that's not the same object as your iris3
>
> Thanks.
>
> Is there a way to iterate over the rows of a data
> frame without writing a loop -- that was my
> original objective.
No. A row of a data frame is still a data frame and therefore arbitrarily
complex.
In any case, in R apply() does write a loop. There are lots of legacy
myths about the efficiencies of loops vs *apply(), but the reality it
depends on the exact version of your S engine (and perhaps on how much
memory you have).
Just for the record, lapply() is the way to iterate over columns of a data
frame.
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list