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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:28:00+00:00 2026-06-12T15:28:00+00:00

I am trying to create a list with the following (nested) structure: l <-

  • 0

I am trying to create a list with the following (nested) structure:

l <- list()
for(i in seq(5)) l[[i]] <- list(a=NA,b=NA)
> str(l)
List of 5
 $ :List of 2
  ..$ a: logi NA
  ..$ b: logi NA
 $ :List of 2
  ..$ a: logi NA
  ..$ b: logi NA
 $ :List of 2
  ..$ a: logi NA
  ..$ b: logi NA
 $ :List of 2
  ..$ a: logi NA
  ..$ b: logi NA
 $ :List of 2
  ..$ a: logi NA
  ..$ b: logi NA

I’d like to do this via rep or similar, as I’m creating a whole bunch of blank lists which I will later fill in. (I’m aware that I can just expand a list via referring to its next index, but that doesn’t work when indexing two-deep).

I thought that rep worked for this, but it does not appear to. ?rep gives the following example:

fred <- list(happy = 1:10, name = "squash")
rep(fred, 5)

Which returns:

> str(rep(fred, 5))
List of 10
 $ happy: int [1:10] 1 2 3 4 5 6 7 8 9 10
 $ name : chr "squash"
 $ happy: int [1:10] 1 2 3 4 5 6 7 8 9 10
 $ name : chr "squash"
 $ happy: int [1:10] 1 2 3 4 5 6 7 8 9 10
 $ name : chr "squash"
 $ happy: int [1:10] 1 2 3 4 5 6 7 8 9 10
 $ name : chr "squash"
 $ happy: int [1:10] 1 2 3 4 5 6 7 8 9 10
 $ name : chr "squash"

In other words, it flattens the list.

I’ve also tried list( rep(fred,5) ) which similarly fails.

How do I replicate a list-of-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-12T15:28:01+00:00Added an answer on June 12, 2026 at 3:28 pm

    I think this has to do with rep behavior, you want to nest before you rep:

    rep(list(fred),5)
    

    The str output:

    List of 5
     $ :List of 2
      ..$ happy: int [1:10] 1 2 3 4 5 6 7 8 9 10
      ..$ name : chr "squash"
     $ :List of 2
      ..$ happy: int [1:10] 1 2 3 4 5 6 7 8 9 10
      ..$ name : chr "squash"
     $ :List of 2
      ..$ happy: int [1:10] 1 2 3 4 5 6 7 8 9 10
      ..$ name : chr "squash"
     $ :List of 2
      ..$ happy: int [1:10] 1 2 3 4 5 6 7 8 9 10
      ..$ name : chr "squash"
     $ :List of 2
      ..$ happy: int [1:10] 1 2 3 4 5 6 7 8 9 10
      ..$ name : chr "squash"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a standard .NET List<T> in F# like this: module
I am trying to create nested repeaters dynamically using ITemplate. This repeater is like
I'm trying to create a list fragment activity like this : public class FluxListeFragment
I'm trying to create a new list of a custom content type following this
I have an the following class I'm trying to create a list of with
I am trying to create a TreeView nested structure with the use of self
I'm trying to parse a nested array structure of the following form: [element [[child1]
Trying to create a list to return some JSON data to a view. Following
I'm trying to create a list in Oz using the following code: local Loop10
I'm trying to create a list of videos that a user may view. This

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.