Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8966797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:05:58+00:00 2026-06-15T17:05:58+00:00

I want to add together all matrices in a list. Here is an example

  • 0

I want to add together all matrices in a list. Here is an example of what I’m trying to do:

## sets up the problem
m1 <- matrix(0,nrow=9,ncol=4)
row.pres <- lapply(1:4,function(x) seq(x,x+2))
m1.l <- lapply(1:4,function(y) {m1[row.pres[[y]],y] <- 1
                        return(m1)}
       )

I want to add up all the elements of m1.l to come up with a single matrix of the same dimension as each of them. Here is my solution:

test <- lapply(1:4,function(x) paste("m1.l[[",x,"]]",sep=''))
add.all <- paste(test,collapse="+")
eval(parse(text=add.all))

But there must be a better way! perhaps something via do.call?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T17:05:59+00:00Added an answer on June 15, 2026 at 5:05 pm
     > Reduce("+", m1.l)
          [,1] [,2] [,3] [,4]
     [1,]    1    0    0    0
     [2,]    1    1    0    0
     [3,]    1    1    1    0
     [4,]    0    1    1    1
     [5,]    0    0    1    1
     [6,]    0    0    0    1
     [7,]    0    0    0    0
     [8,]    0    0    0    0
     [9,]    0    0    0    0
    

    This will add the first two together, then it will take the result and add the 3rd matrix to it. Then it will add that result to the fourth matrix, etc. until it’s worked its way through the whole list.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to add a list of dicts together with python multiprocessing module. Here
Here is a nested hash. We want to add all the value of subtotal
I want to add two maps together with the following behavior. if key exists
I want add label to every row in tableview at right side of the
I want add my custom sidebar next right column all page. Please check this
I have a list of string values that I want add to a hashtable
I have problem, when I want add Node to my GUI from other Thread.
I have 3 textboxes and I want to check if put together they all
After exceuting a xquery expression, the output is all 'together'. How do I add
here am trying to add a comma in the values got by the foreach

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.