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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:45:21+00:00 2026-05-27T03:45:21+00:00

In the R programming language, how do I get a dynamic array ( as

  • 0

In the R programming language, how do I get a dynamic array (as described on Wikipedia) or equivalent data structure? I want something with the following attributes:

  1. O(1) indexing.

  2. Amortized O(1) appending.

  3. O(N) or less wasted space.

  4. Type parametric, i.e. can hold lists, user-defined objects, functions, matrices, etc., not just numbers.

  5. Appending without naming should be supported. Therefore, using an environment won’t cut it.

From what I can tell, using a list doesn’t work because appending to one the following way takes O(N) time, not amortized O(1):

foo <- list()
foo[[length(foo) + 1]] <- 1
  • 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-05-27T03:45:22+00:00Added an answer on May 27, 2026 at 3:45 am

    Instead of appending to the list each time, preallocate it with a fixed length. Then when the list is full, double it, as per the description on the Wikipedia article. This should give you the performance you’re after.

    foo <- vector("list", 1000)
    
    # populate the list, with N >> 1000...
    for(i in seq(N))
    {
        foo[[i]] <- ...
    
        # if the list is full, extend it
        if(i == length(foo))
            foo <- c(foo, vector("list", length(foo)))
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any really low level programming language that can get access the memory
I was trying to get Matz and Flanagan's Ruby Programming Language metaprogramming chapter into
Which programming language would you recommend to learn about data structures and algorithms in?
In his The C++ Programming Language Stroustrup gives the following example for inc/dec overloading:
Is there any [non programming language specific] way to get hex versions of object
I was reviewing the Objective-C Programming Language documentation to get a better understanding of
I've decided to get more acquainted with my favorite programming language, but only reading
Im new to the android programming language and am trying to get an android
I'm want to learn a desktop programming language, preferably C, C++ or C#. I'm
I want to make a mini programming language in mma. From a textfile 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.