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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:42:04+00:00 2026-05-22T01:42:04+00:00

I have a list of dataframes for which I am certain that they all

  • 0

I have a list of dataframes for which I am certain that they all contain at least one row (in fact, some contain only one row, and others contain a given number of rows), and that they all have the same columns (names and types). In case it matters, I am also certain that there are no NA’s anywhere in the rows.

The situation can be simulated like this:

#create one row
onerowdfr<-do.call(data.frame, c(list(), rnorm(100) , lapply(sample(letters[1:2], 100, replace=TRUE), function(x){factor(x, levels=letters[1:2])})))
colnames(onerowdfr)<-c(paste("cnt", 1:100, sep=""), paste("cat", 1:100, sep=""))
#reuse it in a list
someParts<-lapply(rbinom(200, 1, 14/200)*6+1, function(reps){onerowdfr[rep(1, reps),]})

I’ve set the parameters (of the randomization) so that they approximate my true situation.

Now, I want to unite all these dataframes in one dataframe. I thought using rbind would do the trick, like this:

system.time(
result<-do.call(rbind, someParts)
)

Now, on my system (which is not particularly slow), and with the settings above, this takes is the output of the system.time:

   user  system elapsed 
   5.61    0.00    5.62

Nearly 6 seconds for rbind-ing 254 (in my case) rows of 200 variables? Surely there has to be a way to improve the performance here? In my code, I have to do similar things very often (it is a from of multiple imputation), so I need this to be as fast as possible.

  • 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-22T01:42:05+00:00Added an answer on May 22, 2026 at 1:42 am

    Can you build your matrices with numeric variables only and convert to a factor at the end? rbind is a lot faster on numeric matrices.

    On my system, using data frames:

    > system.time(result<-do.call(rbind, someParts))
       user  system elapsed 
      2.628   0.000   2.636 
    

    Building the list with all numeric matrices instead:

    onerowdfr2 <- matrix(as.numeric(onerowdfr), nrow=1)
    someParts2<-lapply(rbinom(200, 1, 14/200)*6+1, 
                       function(reps){onerowdfr2[rep(1, reps),]})
    

    results in a lot faster rbind.

    > system.time(result2<-do.call(rbind, someParts2))
       user  system elapsed 
      0.001   0.000   0.001
    

    EDIT: Here’s another possibility; it just combines each column in turn.

    > system.time({
    +   n <- 1:ncol(someParts[[1]])
    +   names(n) <- names(someParts[[1]])
    +   result <- as.data.frame(lapply(n, function(i) 
    +                           unlist(lapply(someParts, `[[`, i))))
    + })
       user  system elapsed 
      0.810   0.000   0.813  
    

    Still not nearly as fast as using matrices though.

    EDIT 2:

    If you only have numerics and factors, it’s not that hard to convert everything to numeric, rbind them, and convert the necessary columns back to factors. This assumes all factors have exactly the same levels. Converting to a factor from an integer is also faster than from a numeric so I force to integer first.

    someParts2 <- lapply(someParts, function(x)
                         matrix(unlist(x), ncol=ncol(x)))
    result<-as.data.frame(do.call(rbind, someParts2))
    a <- someParts[[1]]
    f <- which(sapply(a, class)=="factor")
    for(i in f) {
      lev <- levels(a[[i]])
      result[[i]] <- factor(as.integer(result[[i]]), levels=seq_along(lev), labels=lev)
    }
    

    The timing on my system is:

       user  system elapsed 
       0.090    0.00    0.091 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have list of objects that contain information about which classes static EventHandler should
I have a long list of dates that i want to parse, they are
I have a script that appends some rows to a table. One of the
If I have List<String> text how can I create a sub-list of all continious
I have a list of integers, List<Integer> and I'd like to convert all the
I have a list, each item of which has several things in it, including
I have a list of bean objects passed into my JSP page, and one
I have a list of vectors which are time series of inequal length. My
I have a list of lists that looks like this: x[[state]][[year]] . Each element
We have list in html: <ul class=list> <li>some text<li> <li>some text<li> <li>some text<li> <li>some

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.