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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:12:52+00:00 2026-06-11T19:12:52+00:00

I have a function which contains a loop over two lists and builds up

  • 0

I have a function which contains a loop over two lists and builds up some calculated data. I would like to return these data as a lists of lists, indexed by some value, but I’m getting the assignment wrong.

A minimal example of what I’m trying to do, and where i’m going wrong would be:

mybiglist <- list()
for(i in 1:5){
    a <- runif(10)
    b <- rnorm(16)
    c <- rbinom(8, 5, i/10)
    name <- paste('item:',i,sep='')
    tmp <- list(uniform=a, normal=b, binomial=c)
    mybiglist[[name]] <- append(mybiglist, tmp)
}

If you run this and look at the output mybiglist, you will see that something is going very wrong in the way each item is being named.

Any ideas on how I might achieve what I actually want?

Thanks

ps. I know that in R there is a sense in which one has failed if one has to resort to loops, but in this case I do feel justified 😉

  • 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-11T19:12:54+00:00Added an answer on June 11, 2026 at 7:12 pm

    It works if you don’t use the append command:

    mybiglist <- list()
    for(i in 1:5){
      a <- runif(10)
      b <- rnorm(16)
      c <- rbinom(8, 5, i/10)
      name <- paste('item:',i,sep='')
      tmp <- list(uniform=a, normal=b, binomial=c)
      mybiglist[[name]] <- tmp
    }
    
    # List of 5
    # $ item:1:List of 3
    # ..$ uniform : num [1:10] 0.737 0.987 0.577 0.814 0.452 ...
    # ..$ normal  : num [1:16] -0.403 -0.104 2.147 0.32 1.713 ...
    # ..$ binomial: num [1:8] 0 0 0 0 1 0 0 1
    # $ item:2:List of 3
    # ..$ uniform : num [1:10] 0.61 0.62 0.49 0.217 0.862 ...
    # ..$ normal  : num [1:16] 0.945 -0.154 -0.5 -0.729 -0.547 ...
    # ..$ binomial: num [1:8] 1 2 2 0 2 1 0 2
    # $ item:3:List of 3
    # ..$ uniform : num [1:10] 0.66 0.094 0.432 0.634 0.949 ...
    # ..$ normal  : num [1:16] -0.607 0.274 -1.455 0.828 -0.73 ...
    # ..$ binomial: num [1:8] 2 2 3 1 1 1 2 0
    # $ item:4:List of 3
    # ..$ uniform : num [1:10] 0.455 0.442 0.149 0.745 0.24 ...
    # ..$ normal  : num [1:16] 0.0994 -0.5332 -0.8131 -1.1847 -0.8032 ...
    # ..$ binomial: num [1:8] 2 3 1 1 2 2 2 1
    # $ item:5:List of 3
    # ..$ uniform : num [1:10] 0.816 0.279 0.583 0.179 0.321 ...
    # ..$ normal  : num [1:16] -0.036 1.137 0.178 0.29 1.266 ...
    # ..$ binomial: num [1:8] 3 4 3 4 4 2 2 3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a recursive function which contains some drawing code inside. I was advised
I have a function which return a loop, now I want to check if
I have foreach function which calls specified function on every element which it contains.
I have a std::atomic which contains a pointer to a member function. Everything compiles
I have a database table which is full-text indexed and i use the CONTAINS-function
hi i have function which is called by tinker listbox so i cannot return
Can I´m asking for advice. I have function which should return javascript object function
I have a function which looks something like this, it returns a noncopyable class
I have a function which I have to loop it a few times but
I have a function which takes two arguments, the ID of an item (wine)

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.