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

If I have a data file with columns of numbers like 3.14 0.42 6.66
I use a form where i have listed the data from database like title,
I have a data set of books and authors, with a many-to-many relationship. There
Problem : I have to create a number of tables for caching some amount
I have been tasked to look after an ASP.Net WebForms application that communicates with
I have a directory full of XML files. For each of these files I
We have a web application (it is a game) with lots of various forms
I have tried again to ask the same question , but I ended up
I'm trying to support multiple databases for an app that I'm writing. The app
Short version: Can we read from dozens or hundreds of table partitions in a

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.