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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:46:15+00:00 2026-05-29T11:46:15+00:00

So I am going to be doing some work with R soon, and I

  • 0

So I am going to be doing some work with R soon, and I need to learn how to use it. I figured a good exercise would be to try to write a program that takes a payoff matrix and does iterated elimination of dominated strategies (if you don’t know what I’m talking about, it’s very simple game theory stuff and not really important to the question). The first step was to write a function that takes a matrix and returns a summary of all strategies that are dominated, but something is going wrong.

strictdomlist <- function(m) {
    # takes a matrix, determines if row player has strictly 
    # dominated strategies
    strategies <- dim(m)[1]
    dominatingstrategies <- list()
    for (i in 1:strategies) {
        dstrat <- 0
        for (j in 1:strategies) {
            if (i != j) {
                if (all(m[i, ]<m[j, ])) dstrat <- c(dstrat,j)
            }
        }
        dominatingstrategies[i] <- dstrat
    }
    return(dominatingstrategies)
}

All (I wish) it’s doing is checking each row to see if there is a row which has entries that are all greater. If there is, it should put the number of that row in a vector, and then at the end, assign that vector to the i-th position in dominatingstrategies. If I give it this matrix:

     [,1] [,2] [,3] [,4]
[1,]    1    4    2   10
[2,]    2    5    9   11
[3,]    0    1    1    1
[4,]   16    7   10   12

I want it to give me back:

[[1]]
[1] 2 4

[[2]]
[1] 4

[[3]]
[1] 1 2 4

[[4]]
[1] 0

But what it’s giving me is:

> strictdomlist(m2)
[[1]]
[1] 4

[[2]]
[1] 4

[[3]]
[1] 4

[[4]]
[1] 0

Warning messages:
1: In dominatingstrategies[i] <- dstrat :
  number of items to replace is not a multiple of replacement length
2: In dominatingstrategies[i] <- dstrat :
  number of items to replace is not a multiple of replacement length
3: In dominatingstrategies[i] <- dstrat :
  number of items to replace is not a multiple of replacement length

Can anyone see what I’m doing wrong? And, if there’s a better way of doing this in R, can you help?

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-29T11:46:15+00:00Added an answer on May 29, 2026 at 11:46 am

    It’s your list assignment:

    dominatingstrategies[i] <- dstrat
    

    To assign into a list, you have to use double square brackets:

    dominatingstrategies[[i]] <- dstrat
    

    When you use single brackets, you extract the list containing the vector contained in dominatingstrategies[i], not the vctor itself.

    Also, since you start your dstrat at 0, you get this matrix out (with the above error fixed):

    > strictdomlist(m)
    [[1]]
    [1] 0 2 4
    
    [[2]]
    [1] 0 4
    
    [[3]]
    [1] 0 1 2 4
    
    [[4]]
    [1] 0
    

    i.e., you get a 0 out in every element, including ones which have greater rows.

    If you don’t want this, you can initialise dstrat as dstrat <- c(), and then at the end do something like

    if (length(dstrat)==0) 
        dominatingstrategies[[i]] <- 0
    else
        dominatingstrategies[[i]] <- dstrat
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an OpenGL program in which I am doing some augmented reality work.
I'm going to be doing some webscraping and my plan is to have something
I have a Python 3 script that is going to be doing some regex
I was doing some work at home over the weekend and used git to
I just started doing some Javascript work for a project, I do mostly backend
I have a windows service doing some repetitive work (wcf calls) after logging programmaticaly
This one has be stumped. I'm doing some work on a legacy ASP.NET WebForms
Checkout my code I have been doing some work on an sms application and
For a class I'm taking I've been doing some work directly with the clone()
I just started doing some Android app development, and I decided I'm going to

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.