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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:57:06+00:00 2026-05-30T04:57:06+00:00

Probably about 20 chars’ solution. I want colnames to matrix(…) -object or alternative way

  • 0

Probably about 20 chars’ solution. I want colnames to matrix(...) -object or alternative way to create 6×100 dataframe with zeros and colnames:

matrix(rep(0,600),ncol=6)->M

where to access things with title-ids likecol$id and now to access 97th element in col a1 in the matrix, I want to do M$a1[97]. How?

Errr

> matrix(rep(0,600),ncol=6,nrow=100, colnames=c('q1','q2','a1','a2','s1','s2'))
Error in matrix(rep(0, 600), ncol = 6, nrow = 12, colnames = c("q1", "q2",  : 
  unused argument(s) (colnames = c("q1", "q2", "a1", "a2", "s1", "s2"))
  • 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-30T04:57:07+00:00Added an answer on May 30, 2026 at 4:57 am

    1) Use the dimnames parameter in matrix to define column names when creating the matrix. dimnames should be a list of 2 or NULL.

    M <- matrix(rep(0,600), ncol = 6, 
                dimnames = list(NULL, c('q1','q2','a1','a2','s1','s2')))
    

    From the help page:

    dimnames    
    A dimnames attribute for the matrix: NULL or a list of length 2 giving the row and column
    names respectively. An empty list is treated as NULL, and a list of length one as row
    names. The list can be named, and the list names will be used as names for the dimensions.
    

    Or set the colnames after the fact:

    colnames(M) <- c('q1','q2','a1','a2','s1','s2')
    

    2) Use the [ indexing operator for matrices:

    > M[97, "a1"]
    a1 
     0 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have another (probably unanswered) question about map views. I have a map view
I'm about to take the plunge and build a PC, and it will probably
From the question you can probably tell that I don't know much about code!
I have a language-agnostic question about an algorithm. This comes from a (probably simple)
Probably a long question for a simple solution, but here goes... I have a
I am about to implement the archetypal FileSystemWatcher solution. I have a directory to
Probably a really simple one this - I'm starting out with C# and need
Probably an easy one: Are there any rules of thumb or pointers that could
Probably not much more to elaborate on here - I'm using a NumericStepper control
Probably a bit off topic question, but it's something I'm really interested in getting

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.