Hi,

Thanks, I was using the square brackets instead of "(". The "(" makes it work.

However, some of my matrices have NA for some values. I need those NA's to 
basically not be counted. And if all the lists have NA for a specific (n,m), I 
want it to remain an (n,m). By using the Reduce('+', mymats), any entries with 
NA in at least one of the lists will give me back an NA for the sum (rather 
than making it NA if it at least on list has an NA for that element).

Thanks again for everyone's help!

Kind regards,
Greg
On Sep 12, 2010, at 4:54 PM, Dennis Murphy wrote:

> Hi:
> 
> Here's a more concrete example of Phil's point.
> 
> mymats <- vector('list', 5)
> set.seed(246)
> 
> # Generate a list of five 3 x 3 matrices
> for(i in 1:5) mymats[[i]] <- matrix(sample(1:9), nrow = 3)
> # Sum them elementwise
> Reduce('+', mymats)
>      [,1] [,2] [,3]
> [1,]   23   33   15
> [2,]   25   36   26
> [3,]   20   24   23
> 
> HTH,
> Dennis
> 
> On Sun, Sep 12, 2010 at 12:52 PM, Gregory Ryslik <rsa...@comcast.net> wrote:
> Hi,
> 
> Doing that I get the following:
> 
> Browse[2]> Reduce["+",results]
> Error in Reduce["+", results] :
>  object of type 'closure' is not subsettable
> 
> You want parentheses there, not brackets; you're asking R to subset a 
> function, Reduce, which is an object of type closure. Hopefully the error 
> message makes more sense now.
>  
> 
> Thanks again!
> 
> Kind regards,
> Greg
> On Sep 12, 2010, at 3:49 PM, Phil Spector wrote:
> 
> > Gregory -
> >   Suppose your list is called "mymats".  Then
> >
> > Reduce("+",mymats)
> >
> > does what you want.
> >                                  - Phil
> >
> >
> > On Sun, 12 Sep 2010, Gregory Ryslik wrote:
> >
> >> Hi,
> >>
> >> I have a list of several hundred 2 dimensional matrices, where each matrix 
> >> is n x m. What I need to do is that for each n,m I  need an average over 
> >> all the lists. This would collapse it down to just one nxm matrix. Any 
> >> easy ways to do that? As always, I'd like to avoid a for loop to keep 
> >> computational time low! Thanks again everyone!
> >>
> >> Cheers,
> >> G
> >> ______________________________________________
> >> R-help@r-project.org 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@r-project.org 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.
> 


        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org 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.

Reply via email to