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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:03:02+00:00 2026-06-02T05:03:02+00:00

Hi I have a file having a structure as follows 12 45 56 34

  • 0

Hi I have a file having a structure as follows

12    45    56
34    65    31
12    23    43

and so on I have a huge dataset

so I have text file having 3 columns but, the way I want to create the sparse matrix is that for each line say 12 45 56….. first number i.e is the row second number i.e 45 is column and third number(i.e 56) is the value at 12th row and 45th column of the sparse matrix

I do the following

>x = scan('data.txt',what=list(integer(),integer(),numeric()))
Read 61944406 records

> library('Matrix')
Loading required package: lattice
N
> N= sparseMatrix(i=x[[1]],j=x[[2]],x=x[[3]])

but I get this error

Error in validObject(r) : 
invalid class “dgTMatrix” object: all row indices (slot 'i') must be between 0 and nrow-1 in a TsparseMatrix

could anyone help me figure out what I am doing wrong?

  • 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-02T05:03:04+00:00Added an answer on June 2, 2026 at 5:03 am

    When you use x[[1]] you are refering to the first element of you x matrix, in this case x[[1]]=12. You must use x[,1] if you want index columms or x[1,] for rows.
    Try this:

    x = matrix(c(12,45,56,
                 34,65,31,
                 12,23,43), nrow=3, byrow=TRUE)
    
    N= sparseMatrix(i=x[,1], j=x[,2], x=x[,3])
    

    EDITED: I have reproduced your error:

    x = matrix(c( 0,45,56,
                 34,65,31,
                 12,23,43), nrow=3, byrow=TRUE)
    
    N= sparseMatrix(i=x[,1], j=x[,2], x=x[,3])
    Error en validObject(r) : 
      invalid class “dgTMatrix” object: all row indices (slot 'i') must be between 0 and nrow-1 in a TsparseMatrix
    

    So, make sure you don’t have 0 in your 2 first colums

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

Sidebar

Related Questions

I have a .txt file having some text. I want to read this file
I have a text file having words that i need to validate. After following
I'm having trouble with PHP text parsing I have a txt file which has
I am having utf-8 encoded file containing arabic text and I have to search
I have a file file.txt having the following structure:- ./a/b/c/sdsd.c ./sdf/sdf/wer/saf/poi.c ./asd/wer/asdf/kljl.c ./wer/asdfo/wer/asf/asdf/hj.c How
Suppose I have an XSD file having below lines of code; <xsd:simpleType name=test> <xsd:restriction
I have a flash file menu i am having problem while link it to
I am having following issue with reading binary file in C. I have read
I have a *.txt files having integers, one on each line. So the file
Hi I am having trouble getting an embedded js file to work. I have

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.