[R-lang] apply through a list
Joan Bresnan
bresnan at stanford.edu
Wed May 16 12:18:06 PDT 2007
Are you looking for lapply?
lapply package:base R Documentation
Apply a Function over a List or Vector
Description:
'lapply' returns a list of the same length as 'X', each element of
which is the result of applying 'FUN' to the corresponding element
of 'X'.
'sapply' is a "user-friendly" version of 'lapply' by default
returning a vector or matrix if appropriate.
'replicate' is a wrapper for the common use of 'sapply' for
repeated evaluation of an expression (which will usually involve
random number generation).
Usage:
lapply(X, FUN, ...)
sapply(X, FUN, ..., simplify = TRUE, USE.NAMES = TRUE)
On 5/16/07, Michael Cysouw <cysouw at eva.mpg.de> wrote:
> a general question, not specific to linguistics...
>
> I have a (large) set of same-size matrices M1,M2,M3,... which I
> stored in a list. How do I apply a function over the same position of
> all matrices? For example, take the sum M1+M2+M3+...
>
> I have not found any "apply" like variant that would do the trick.
> Any suggestions?
>
> best
> michael
>
>
> —————————————————————————
> Michael Cysouw
>
> Department of Linguistics
> Max Planck Institute for Evolutionary Anthropology
> Deutscher Platz 6
> D-04103 Leipzig
>
> Room: U 1.14
>
> phone: +49 (0) 341 35 50 316
> fax: +49 (0) 341 35 50 333
> home: +49 (0) 341 22 59 488
> mobile: +49 (0) 172 18 33 507
> e-mail: cysouw at eva.mpg.de
> homepage: http://www.eva.mpg.de/~cysouw/
> —————————————————————————
>
>
>
> _______________________________________________
> R-lang mailing list
> R-lang at ling.ucsd.edu
> https://ling.ucsd.edu/mailman/listinfo.cgi/r-lang
>
--
Joan Bresnan
Stanford University
http://www.stanford.edu/~bresnan/
More information about the R-lang
mailing list