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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:20:43+00:00 2026-05-20T06:20:43+00:00

I have a number of operations on data frames which I would like to

  • 0

I have a number of operations on data frames which I would like to speed up using mclapply() or other lapply() like functions. One of the easiest ways for me to wrestle with this is to make each row of the data frame a small data frame in a list. I can do this pretty easily with plyr like this:

df <- data.frame( a=rnorm(1e4), b=rnorm(1e4))
require(plyr)
system.time(myList <- alply( df, 1, function(x) data.frame(x) ))

Once I have my data as a list I can easily do things like:

mclapply( myList, function(x) doSomething(x$a) )

This works swimmingly, but I have quite a lot of data and the adply() step is quite slow. I tried using the multicore parallel backend on the adply step, but it never used more than one processor even though I had registered 8. I’m suspicious the parallel option may not work with this type of problem.

Any tips on how to make this faster? Maybe a base R solution?

  • 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-20T06:20:44+00:00Added an answer on May 20, 2026 at 6:20 am

    Just use split. It’s a few times faster than your adply line.

    > system.time(myList <- alply( df, 1, function(x) data.frame(x) ))
       user  system elapsed 
       7.53    0.00    7.57 
    > system.time( splitList <- split(df, 1:NROW(df)) )
       user  system elapsed 
       1.73    0.00    1.74 
    > 
    

    I suspect the parallel backend on adply is only for function evaluation (not splitting and re-combining).

    UPDATE:
    If you can convert your data.frame to a matrix, the solution below will be über-fast. You may be able to use split, but it will drop names and return a vector in each list element.

    > m <- as.matrix(df)
    > system.time( matrixList <- lapply(1:NROW(m), function(i) m[i,,drop=FALSE]) )
       user  system elapsed 
       0.02    0.00    0.02
    > str(matrixList[[1]])
     num [1, 1:2] -0.0956 -1.5887
     - attr(*, "dimnames")=List of 2
      ..$ : NULL
      ..$ : chr [1:2] "a" "b"
    > system.time( matrixSplitList <- split(m, 1:NROW(m)) )
       user  system elapsed 
       0.01    0.00    0.02 
    > str(matrixSplitList[[1]])
     num [1:2] -0.0956 -1.5887
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data file, with each line having one number, like 10 20
I have to convert a decimal number to octal and hexadecimal using bitwise operations.
I have repository to manage operations on ComplaintTypes which has a large number of
My situation is : I have a number of client applications, which is using
I have a number of classes and they are quite close to each other
We have a number of data objects that realize INotifyPropertyChanged to allow for WPF
I have a number of classes (more than 40), each one has a number
I have a various data.frames with columns of the same length where I am
We have a device which has a 10 byte serial number which must be
I have a page which performs following operations: Executes a query in a DB

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.