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 6214879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:57:14+00:00 2026-05-24T06:57:14+00:00

I am currently working in R and I am trying to populate a matrix

  • 0

I am currently working in R and I am trying to populate a matrix with
a some for loops. However, I keep getting the “number of items to replace is not a multiple of replacement length” error. The way I set my matrix() is that I specified nrow
(because I am sure of the size) and I leave the ncol blank.

How can I create a matrix that dynamically allocate the dimensions?

Any recommendations?
Thank you.

  • 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-05-24T06:57:15+00:00Added an answer on May 24, 2026 at 6:57 am

    A couple of options spring to mind:

    • Make an informed guess as to the size of the matrix and allocate accordingly. Then have your code check to see if you would exceed the limits chosen and expand the object. If you expand by a reasonable chunk size (i.e. don’t add just 1 column, add 10 or 20 or n depending on the size of your problem, whatever is reasonable) then you won’t incur the copy/expand overhead that often, which is what bogs loops down if written badly.

    • Store the data/result in a list, each component of which would be one row of your matrix. That way you fill in the object as you go along, and then can either process the resulting list into a matrix with padding, or just work directly with the list. If each row can be of a different length (number of columns) then it doesn’t make sense to store as a matrix in the first place and the list is the better option.

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

Sidebar

Related Questions

I'm trying to make a drawing app and currently working on the line tool
I'm currently working on a little project in which I'm trying to create a
I am currently working on an android project and I am trying to create
I'm currently working on a ASP.Net 3.5 project and trying to implement session timeout
I am currently working on an Android app and I am trying to get
I'm trying to play a random sound onTouch event (currently working), but the sound
Here's the code I'm currently working with: http://jsfiddle.net/gEMCm/ I'm trying to make an image
I'm currently working on a project using netbeans 6.9 and grails 1.3. I'm trying
Currently I'm working on Text to speech in android and I'm trying to build
I am trying to get MSTest working with CruiseControl.Net. I currently have it working

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.