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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:35:31+00:00 2026-06-06T16:35:31+00:00

UPDATE see below I am not sure how to populate a list or vector

  • 0

UPDATE see below

I am not sure how to populate a list or vector with elements in a while loop when there is no counter/iterator to index by. See below minimal example. I have a more complicated while loop that, like foo below, has a logical statement that doesn’t include a number, so it’s not clear to me how to populate the list vec with x. Is it possible to create some kind of iterator within the while loop so that each time you go through the while loop the iterator simply increases by one? I could then use this iterator to index the list vec?

foo <- function(){
  names <- list("a","b","c")
  vec <- list()
  more <- TRUE
  while(more == TRUE){
   names <- rep(names, 2)
   if(length(names) < 50) vec <- names
   more <- length(names) < 50
   }
  vec
}

foo()

Thanks, this seems to work as I wanted now:

foo <- function(){
  names <- list("a","b","c")
  i <- 0
  vec <- list()
  more <- TRUE
  while(more == TRUE){
    i <- i + 1
    names <- rep(names, 2)
    if(length(names) < 50) vec[[i]] <- names
    more <- length(names) < 50
  }
 vec
}

foo()
  • 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-06T16:35:32+00:00Added an answer on June 6, 2026 at 4:35 pm

    Using the approach where you construct your own iterator is very easy. Here is some example code that prints the numbers 1 through 10 in what could possibly be the least R like way to accomplish this task:

    i <- 0
    more <- TRUE
    while(more == TRUE){
        i <- i + 1
        print(i)
        if(i == 10){
            more <- FALSE
        }
    }
    

    As you can see it’s pretty much exactly like you describe. You just increase the iterator at the top of the loop.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

UPDATE (spoiler): This question is answered (see David Carlisle answere below) and it looks
UPDATED See post #3 below. There is a need to upload a file to
Update: See the bottom of this question for a C# workaround. Hi there, Consider
OLD QUESTION, SEE BELOW FOR THE UPDATED VERSION My development environment is not the
UPDATE : I asked this question in another form (see below), and it got
UPDATE: I actually found the solution myself, see below. In R I want to
Bug reported as fixed by Apple, see accepted answer below ... UPDATE MON AUG
ORIGINAL (see UPDATED QUESTION below) I am designing a new laboratory database that tests
Updated question, see below I'm starting a new project and I would like to
OK, I thought I would try one last update and see if it gets

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.