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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:14:52+00:00 2026-05-12T08:14:52+00:00

Realizing that loops are usually not ideal in R, sometimes they are necessary. When

  • 0

Realizing that loops are usually not ideal in R, sometimes they are necessary.

When writing large loops, doesn’t

for (i in 1:large_number) 

waste memory, since a vector of size large_number must be created?

Would this make while loops the best choice for large, necessary loops?

  • 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-12T08:14:52+00:00Added an answer on May 12, 2026 at 8:14 am

    First off, a lot of that ‘loops are bad’ chatter stems from the dark ages when loops where in fact less efficiently implemented, in particular in some versions of S-Plus.

    That said, and while your comment about the need for a large index object is correct, you could also use

    • functions from the apply family such as sapply, lapply or tapply to unroll your structures

    • the relatively new iterators package which also avoids the large vector you mentioned as a memory constraint

    • the Ra ‘accelerated R’ variant and its jit package which can significantly accelerate simple loops.

    As added bonus, options one and two give a path towards parallel execution of the loops on suitable systems using tools from the CRAN packages snow, multicore, or NWS just to name a few.

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

Sidebar

Related Questions

Update: I updated this after doing some digging and realizing that this might be
I'm working with Windows CE 5 and, before realizing that this was the wrong
In a multithreaded Java application, I just tracked down a strange-looking bug, realizing that
Does anyone know of any good image resizing libraries that will handling resizing large
I'm tasked with writing an application that acts as a central storage point for
I am writing a web page that has a vertical menu bar on the
I am just learning OpenGL, and I'm realizing that for more complex shader effects,
I am writing a script that processes some mmaps concurrently with multiprocessing.Process and updates
The Android developer documentation has a very large header -- one that becomes obnoxious
The .NET libraries do an excellent job at resizing images that look great: Bitmap

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.