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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:46:15+00:00 2026-06-18T15:46:15+00:00

I have a problem with appending values to a data frame using parallel processing.

  • 0

I have a problem with appending values to a data frame using parallel processing.

I have a function that will do some calculation and return a dataframe, including these calculation is a random sampling.

so what i did is :

randomizex <- function(testdf)
{
    foreach(ind=1:1000)%dopar%
    {
      testdf$X = sample(testdf$X,nrow(testdf), replace=FALSE)
      fit = lm(X ~ Y, testdf)
      newdf <- rbind(newdf, data.frame(pc=ind, err=sum(residuals(fit)^2) ))

    }

return(newdf)
}
resdf = randomizex(mydf)

when i view the result of resdf, it’s empty

if i replace %dopar% with %do% the result is calculated correctly but it’s too slow ..

is there anyway to boost this a bit ??

  • 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-18T15:46:17+00:00Added an answer on June 18, 2026 at 3:46 pm

    I think you need to read the docs for foreach. Your code block should compute a single part, then you should use the .combine option to say how to join them all together. Look at the examples in the help(foreach) for more guidance. Its not a straight replacement for a for loop.

    For example:

    > resultdf = foreach(i=1:10,.combine=rbind)%dopar%{data.frame(x=runif(4),i=i)}
    > resultdf
                x  i
    1  0.23794248  1
    2  0.15536320  1
    3  0.58609635  1
    4  0.98780497  1
    5  0.97806482  2
    6  0.92440741  2
    7  0.13416121  2
    8  0.81598340  2
    9  0.13834423  3
    [etc]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data frame that I am running a Monte Carlo simulation on,
I have a data-analysis question, that I could easily solve with some T-SQL or
I have a string builder object and I am appending some values to it,
I have problem with my query on C, I’m using the oci8 driver. This
I have problem while loading data into html select when users press or click
I have problem SIMILAR to preventing form data reposting, but not quite the same
I have a form that posts to a php handler which saves the data
I have a problem with form , the problem is that I can't show
I've got a problem with some XSLT transformations. In my XML data there are
I have fixed the problem of it not listing the data which was related

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.