[Zooimage-commits] r97 - pkg/zooimage/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Apr 21 11:39:01 CEST 2009
Author: romain
Date: 2009-04-21 11:39:00 +0200 (Tue, 21 Apr 2009)
New Revision: 97
Modified:
pkg/zooimage/R/utilities.r
Log:
make list.reduce out of list.add
Modified: pkg/zooimage/R/utilities.r
===================================================================
--- pkg/zooimage/R/utilities.r 2009-04-21 09:35:16 UTC (rev 96)
+++ pkg/zooimage/R/utilities.r 2009-04-21 09:39:00 UTC (rev 97)
@@ -424,12 +424,16 @@
# }}}
# {{{ Add items across two lists (names must be the same)
-list.add <- function( ..., .list = list(...) ){
+list.add <- function( ..., .list = list(...), FUN = "+"){
+ list.reduce( .list= .list, FUN = FUN)
+}
+
+list.reduce <- function( ..., .list = list(...), FUN = "+" ){
.list <- .list[ !sapply( .list, is.null) ]
if( length(.list) == 1 ) return( .list[[1]] )
n <- length( .list[[1]] )
out <- lapply( 1:n, function(i){
- Reduce( "+", lapply( .list , "[[", i ) )
+ Reduce( FUN, lapply( .list , "[[", i ) )
} )
attributes( out ) <- attributes( .list[[1]] )
out
More information about the Zooimage-commits
mailing list