[R] lapply and for

About this list Date view Thread view Subject view Author view Attachment view

From: Agustin Lobo (alobo@ija.csic.es)
Date: Mon 23 Jul 2001 - 07:45:04 EST


Message-id: <Pine.OSF.3.96.1010722234411.13791A-100000@ija.csic.es>


Given a list as such:

> milista
$"1":
[1] 23 25 11

$"2":
[1] 34 2

$"3":
[1] 12 1 0 1050 2

What's faster:

> a <- NULL
> for (i in names(milista)){
+ a <- c(a,(mean(milista[[i]])))
+ }

or

a <- lapply(milista,mean)

?

(I understand that the second option
is nicer and more compact, but is it
faster?).

Thanks

Agus

Dr. Agustin Lobo
Instituto de Ciencias de la Tierra (CSIC)
Lluis Sole Sabaris s/n
08028 Barcelona SPAIN
tel 34 93409 5410
fax 34 93411 0012
alobo@ija.csic.es

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Wed 10 Mar 2004 - 08:18:21 EST