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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T17:54:06+00:00 2026-06-18T17:54:06+00:00

I have a list where each list element itself holds another list with several

  • 0

I have a list where each list element itself holds another list with several names objects. Each of these named object is a vector of the same length. My goal is to efficiently combine the related objects (those of the same name) into a matrix by concatening vectors.

Here’s an example of the type of structure I’m working with. However, in the current application it’s coming from mclapply as it is a parallelized multilevel model, and I don’t think there’s a way around getting a list of lists back.

> test=lapply(1:2,function(x){out = list(); out$t=rnorm(3)+x; out$p =rnorm(3)+ x+.1; return(out)})
> test
[[1]]
[[1]]$t
[1] 0.5950165 0.8827352 0.5614947

[[1]]$p
[1] 2.6144102 1.9688743 0.6241944


[[2]]
[[2]]$t
[1] 2.562030 1.832571 3.018756

[[2]]$p
[1] 1.7431969 0.5305784 2.6935106

Here’s a crude way to accomplish what I want

> t.matrix = cbind(test[[1]]$t,test[[2]]$t)
> t.matrix
           [,1]     [,2]
[1,]  2.2094525 2.634907
[2,] -0.2822453 2.440666
[3,]  1.1704518 2.483424

but instead I’d like to be able to do this for a very long list (around 1 million elements), and my current solution doesn’t scale.

I suppose I could use a for loop, but it seems like there must be a better way to do it with clever use of reduce or unlist or sapply or something like that.

  • 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-18T17:54:08+00:00Added an answer on June 18, 2026 at 5:54 pm
    test <- lapply(1:4, function(x) { 
              out = list(); out$t=rnorm(3)+x; out$p =rnorm(3)+ x+.1; return(out)})
    
    do.call(cbind, lapply(test, function(X) X[["t"]]))
    ## do.call(cbind, lapply(test, "[[", "t"))          ## Or, equivalently 
    #           [,1]      [,2]     [,3]     [,4] 
    # [1,] 0.7382887 0.9248296 4.205222 5.847823 
    # [2,] 3.0321069 3.6806652 3.324739 3.695195 
    # [3,] 2.3611483 1.9305901 1.574586 4.287534 
    

    Or, to process both sets of list elements at once:

    elems <- c("t", "p")
    sapply(elems, function(E) {
         do.call(cbind,
                 lapply(test, function(X) {
                     X[[E]]
                 }))
    }, simplify=FALSE)
    # $t
    #           [,1]       [,2]     [,3]     [,4]
    # [1,] 1.9226614 0.66463844 2.558517 2.743381
    # [2,] 3.0026400 0.03238983 2.195404 3.824127
    # [3,] 0.9371057 3.54638107 2.968717 2.434471
    # 
    # $p
    #           [,1]     [,2]     [,3]     [,4]
    # [1,] 0.8544413 2.942780 4.693698 4.158212
    # [2,] 0.7172070 2.381438 4.869630 3.503361
    # [3,] 3.1369674 2.464447 2.484968 3.626174
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an unordered list and each list element contains a photo and a
I have a list of lists that looks like this: x[[state]][[year]] . Each element
I have a singly-linked list containing 1 value in each element. struct listElement {
OK, I have a list ( <ul> ) then inside each <li> element I
I have a list of core data objects each has a longitude and latitude
I have a list where each element is a 5*5 matrix. Eg [[1]] V1
I have an unordered list (each list element contains some further markup but this
I have list where each element is a dictionary. myList = [ {mykey1:myValue1, myKey2:myValue2},
I have a List<> of type world and within each world element is a
I have a list where elements are hidden for multiple reasons, each corresponding 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.