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

  • Home
  • SEARCH
  • 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 6741613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:44:42+00:00 2026-05-26T11:44:42+00:00

So, I have a script which I would like to create a matrix or

  • 0

So, I have a script which I would like to create a matrix or data.frame on the fly.

However, I do not know the dimensions of the matrix/frame going in. When I try to just create a blank matrix and adding values, I get the “subscript out of bounds” error,

Here is some of my code:

data <- read.csv("C:/3PP/data.txt", header=F)

parsed = matrix()
for (i in 1:nrow(data))
{
  parsed[data[i,1],data[i,2]+1] = data[i,3]
}

How can I set this up such that this matrix can be generated on the fly, without having to specify the size in the beginning?

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-26T11:44:43+00:00Added an answer on May 26, 2026 at 11:44 am

    Given your problem, you know already the number of rows and columns. You can specify your matrix like:

    parsed <- matrix(nrow=max(Data[,1]),
                     ncol=max(Data[,2])+1)
    

    The only other way to grow a matrix is by using rbind() or cbind(), but that can get pretty slow with big matrices.

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

Sidebar

Related Questions

I have a Bash shell script in which I would like to pause execution
I would like to create a Makefile which also creates a simple script for
I have a few IPython scripts which have redundant functionality. I would like to
I have a script which creates a user-defined object like this: obj = new
I would like to create an ASP.NET MVC web application which has extensible logic
I have a specific case here in which I would like some security advice.
i have written a c program to which i pass in a script like
Question for Python 2.6 I would like to create an simple web application which
I have a little script here which uses DOMDocument to get my data from
I have a shell script which I'd like to trigger from a J2EE web

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.