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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:01:16+00:00 2026-05-23T09:01:16+00:00

I’m writing some code to perform some game theory simulations. My world has several

  • 0

I’m writing some code to perform some game theory simulations.
My “world” has several states (say 2 in my case), it also has several players (again, 2), and each player has a matrix of payouts (2 by 2).

I tried creating the following multi-dimensional array in R:

U = array(2,2,2,2)
U[1][1] = cbind(c(0.7,0.3),c(0.3,0.7))

and I receive the following error:

number of items to replace is not a multiple of replacement length

I can move to using a list, in which each item will be a list of two items, A and B, where A and B are 2×2 matrices. However, I think that performing operations on the lists will become slowly annoying and vectorization will be hard.

Is there a suggestion on the proper implementation or an explanation on why the above code doesn’t work?

Update: Apparently the proper syntax would be:

U[1,1, , ] = cbind(c(0.7,0.3),c(0.3,0.7))

My question still stands – which is better, multi-dimensional vectors or list of tuples?

Thanks,

  • Ron
  • 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-23T09:01:17+00:00Added an answer on May 23, 2026 at 9:01 am

    This code cannot possible work, and you should at least try it for yourself:

    array(2,2,2,2)  ## results in unused argument error
    

    I think you want a 4D array

    U <- array(0, dim = c(2,2,2,2))
    

    and then to assign to a 2D portion use R’s ?Extract syntax

    U[1,1,,] <- cbind(c(0.7,0.3),c(0.3,0.7))
    

    The code U[1][1] can be understand in terms of U being treated as if were a vector with no “dim” attribute (just the numbers in a vector, no dimension structure). The first [1] extracts the first element, returning a single element vector and the second [1] in turn redundantly extracts the first element from that single element vector.

    In terms of understanding what U[1,1,,] is: this is a 2D matrix that is a subset of the 4D array U, specified by taking the first slice from the first and second dimensions, and every slice from the third and fourth dimensions.

    The error you see comes from the fact that you are trying to assign a 2D matrix into a single element of U – but there’s only one slot and the structure and size of the first element is different to the matrix you are trying to crush into it.

    The singleton dimensions (first and second) that have only one slice from the extracted subset are dropped (by default) from the result. This can be avoided by specifying:

    U[1, 1, , , drop = FALSE]
    

    which would give a 4D array, but one with two “degenerate” dimensions i.e. [1, 1, 2, 2] where the first two are kind of redundant (but the sense of that really depends on your purpose). This part is not really relevant to the issue of assigning new values to a subset of the original array, but it might help your understanding.

    Whether an array or a list is best for you depends on what you would like to do, so I’d recommended re-asking your question and focussing on those needs.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string

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.