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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:07:04+00:00 2026-06-11T20:07:04+00:00

Is this a bug in R or does it make sense? ## works aa

  • 0

Is this a bug in R or does it make sense?

## works
aa <- matrix(nrow=1,ncol=2)
dimnames(aa)[[2]] <- c("a","b")
dimnames(aa)[[1]] <- c("c")

## does not work
bb <- matrix(nrow=1,ncol=2)
dimnames(bb)[[1]] <- c("c")
Error in dimnames(bb)[[1]] <- c("c") : 'dimnames' must be a list

Thanks for explanations !

  • 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-11T20:07:06+00:00Added an answer on June 11, 2026 at 8:07 pm

    This is expected behavior. When you assign to an index of an element of an object, R will create the element if it doesn’t exist. In your example “dimnames” doesn’t exist in aa, so R tries to create “dimnames” based on what you’re assigning to it. Consider assigning elements named “a”, “b”, and “c” of a list:

    > L <- list()
    > L$a[[1]] <- 5
    > L$b[[3]] <- "foo"
    > L$c[[4]] <- c(1,2,3)
    > class(L$a)
    [1] "numeric"
    > class(L$b)
    [1] "character"
    > class(L$c)
    [1] "list"
    

    Now the problem with saying L$a[[1]] <- anything is that L$a doesn’t exist yet. What happens when an element doesn’t exist is that R just creates the simplest type of element that would work. As you can see, L$a[[1]] <- 5 would make sense if L$a is a numeric vector, so R makes it a numeric vector. L$b[[3]] <- "foo" doesn’t make sense if L$b is a numeric vector, but it would make sense if L$b is a character vector, so that’s what R creates. But L$c[[4]] <- c(1,2,3) can only happen if L$c is a list, so in that case you get a list.

    In your case, it tries to create dimnames according to that rule; so it makes dimnames(aa) a list, but it only makes dimnames(bb) a character vector. But dimnames has an extra constraint that it has to be a list, so it objects and you get an error.

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

Sidebar

Related Questions

Does anyone know if this subversion bug has been dealt with? https://svn.apache.org/repos/asf/subversion/tags/1.6.9/www/faq.html#windows-access-denied I'm getting
I am trying to detetct/work around this bug in RSS elements. That means I
Is there anyone who can answer this? It really doesn't make sense and I
UPDATE 2011.09.13 This bug has been resolved by Adobe. The example code below now
We have this bug that only appears 30% of the time for the Release
EDIT : As of 2012-06-11 this bug has been finally fixed! https://bugs.webkit.org/show_bug.cgi?id=35981#c1 I have
I have recently discovered that I am affected by this bug http://www.mail-archive.com/mono-bugs@lists.ximian.com/msg71515.html Well, at
I have some data, like this: BUG DATE STATUS ---- ---------------------- -------- 9012 18/03/2008
Is this a bug? When I click 'Create New Action Type' on the Open
Is this a bug in jQueryUI's dialog or is there some reason this is

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.