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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:53:19+00:00 2026-06-03T13:53:19+00:00

As we all know R isn’t the most efficient platform to run large analyses.

  • 0

As we all know R isn’t the most efficient platform to run large analyses.
If I had a large data frame containing three parameters:

GROUP   X  Y
A       1  2
A       2  2
A       2  3
...
B       1  1
B       2  3
B       1  4
...
millions of rows

and I wanted to run a computation on each group (e.g. compute Pearson’s r on X,Y) and store the results in a new data frame, I can do it like this:

df = loadDataFrameFrom( someFile )
results = data.frame()
for ( g in unique( df$GROUP)) ){
    gdf <- subset( df, df$GROUP == g )
    partialRes <- slowStuff( gdf$X,gdf$Y )
    results = rbind( results, data.frame( GROUP = g, RES = partialRes ) )
}
// results contains all the results here.
useResults(results)

The obvious problem is that this is VERY slow, even on powerful multi-core machine.

My question is: is it possible to parallelise this computation, having for example a separate thread for each group or a block of groups?
Is there a clean R pattern to solve this simple divide et impera problem?

Thanks,
Mulone

  • 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-03T13:53:20+00:00Added an answer on June 3, 2026 at 1:53 pm

    First off, R is not necessarily slow. Its speed depends largely on using it correctly, just like any language. There are a few things that can speed up your code without altering much: preallocate your results data.frame before you begin; use a list and matrix or vector construct instead of a data.frame; switch to use data.table; the list goes on, but The R Inferno is an excellent place to start.

    Also, take a look here. It provides a good summary on how to take advantage of multi-core machines.

    The “clean R pattern” was succinctly solved by Hadley Wickam with his plyr package and specifically ddply:

    library(plyr)
    library(doMC)
    registerDoMC()
    ddply(df, .(GROUP), your.function, .parallel=TRUE)
    

    However, it is not necessarily fast. You can use something like:

    library(parallel)
    mclapply(unique(df$GRUOP), function(x, df)  ...)
    

    Or finally, you can use the foreach package:

    foreach(g = unique(df$Group), ...) %dopar$ {
       your.analysis
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this isn't best practice, but can I include all of the dependencies
We all know that most applications out there assume class names to follow the
I know this isn't exactly programming related per se, but programmers are the most
I know this isn't strictly a programming question but y'all must have experienced this.
I know this isn't a unique issue but I've not had much luck finding
As you all know since it is one of the most asked topic on
As you all know to send data through Activity I have to use the
We all know Jmeter isn't the best at changing the number of active threads
We all know that CSS sprite images are great to reduce the amount of
We all know the effects that lots of thrown exceptions can have over the

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.