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

  • Home
  • SEARCH
  • 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 8945743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:19:25+00:00 2026-06-15T12:19:25+00:00

I have a list prob with 50 elements. Each element is a 601×3 matrix

  • 0

I have a list prob with 50 elements. Each element is a 601×3 matrix of probabilities, each row of which represents a complete sample space (i.e., each row of each matrix sums to 1). For instance, here are the first five rows of the first element of prob:

> prob[[1]][1:5,]

           [,1]      [,2]       [,3]
 [1,] 0.6027004 0.3655563 0.03174335
 [2,] 0.6013667 0.3665756 0.03205767
 [3,] 0.6000306 0.3675946 0.03237481
 [4,] 0.5986921 0.3686131 0.03269480
 [5,] 0.5973513 0.3696311 0.03301765

Now, what I want to do is to create the following matrix for each row of each matrix/element in the list prob. Taking the first row, let a = .603, b = .366, and c = .032 (rounding to three decimal places). Then,

> w
         [,1]       [,2]       [,3]
 [1,] a*(1-a)       -a*b       -a*c
 [2,]    -b*a    b*(1-b)       -b*c
 [3,]    -c*a       -c*b    c*(1-c)

Such that:

> w
           [,1]       [,2]       [,3]
 [1,]  0.239391  -0.220698  -0.019296
 [2,] -0.220698   0.232044  -0.011712
 [3,] -0.019296  -0.011712   0.030976

I want to obtain a similar 3×3 matrix 600 more times (for the rest of the rows of this matrix) and then to repeat this entire process 49 more times for the rest of the elements of prob. The only thing I can think of is to call apply within lapply so that I am accessing each row of each matrix one-at-a-time. I’m sure that is not an elegant way to do this (not to mention I can’t get it to work), but I can’t think of anything else. Can anyone help me out with this? I’d also love to hear suggestions for using a different structure (e.g., is it bad to use matrices within lists?).

  • 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-15T12:19:26+00:00Added an answer on June 15, 2026 at 12:19 pm

    Running this process with lapply on a list of similarly dimensioned matrices should be very simple. If it represents a challenge, then you should post the dput(.) output for a two element list with similar matrices. The challenge is really to do the processing row by row which is illustrated here with the output being a 3x3xN array:

    w <- apply(M, 1, function(rw) diag( rw*(1-rw) ) + 
                        rbind( rw*c(0, -rw[1], -rw[1] ), 
                               rw*c(-rw[2],0, -rw[2] ),
                               rw*c(-rw[3], -rw[3], 0)
             )
    
     )
     w
                 [,1]        [,2]        [,3]        [,4]        [,5]
     [1,]  0.23945263  0.23972479  0.23999388  0.24025987  0.24052272
     [2,] -0.22032093 -0.22044636 -0.22056801 -0.22068575 -0.22079962
     [3,] -0.01913173 -0.01927842 -0.01942588 -0.01957412 -0.01972314
     [4,] -0.22032093 -0.22044636 -0.22056801 -0.22068575 -0.22079962
     [5,]  0.23192489  0.23219793  0.23246881  0.23273748  0.23300395
     [6,] -0.01160398 -0.01175156 -0.01190081 -0.01205173 -0.01220435
     [7,] -0.01913173 -0.01927842 -0.01942588 -0.01957412 -0.01972314
     [8,] -0.01160398 -0.01175156 -0.01190081 -0.01205173 -0.01220435
     [9,]  0.03073571  0.03102998  0.03132668  0.03162585  0.03192748
    
     w <- array(w, c(3,3,5) )
     w
    , , 1
    
                [,1]        [,2]        [,3]
    [1,]  0.23945263 -0.22032093 -0.01913173
    [2,] -0.22032093  0.23192489 -0.01160398
    [3,] -0.01913173 -0.01160398  0.03073571
    
    , , 2
    
                [,1]        [,2]        [,3]
    [1,]  0.23972479 -0.22044636 -0.01927842
    [2,] -0.22044636  0.23219793 -0.01175156
    [3,] -0.01927842 -0.01175156  0.03102998
    
    .... snipped remaining output
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have list of some data items. Each has a method GetStyle which returns
I have List I want to sort Desc by Priority, which is int and
I have list of files which contain particular patterns, but those files have been
I have a jcombobox which values come from a list. I want to first
i have List of int which consists of value 0,0,0,1,2,3,4,0,0 now i like to
I have Projelements , which are like: Milestone Task ... etc ... Each Projelement
I have list of string which I want to add as option in select
I have list of restaurant details along with menus which i got from singleplatform.
I have a ListAdapter which is used to display a list in the Listview
I have a recursive method which is simplified below: private List<string> data; public 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.