0

I have a list containing 1000 data frames that should be of identical size and structure. Each of the data frames contains 1 row and 8 columns. I am trying to convert this into a single data frame with 1000 rows and 8 columns. When I run the code to do this I get:

dat <- do.call(rbind, b6000)
Error in rbind(deparse.level, ...) : 
  numbers of columns of arguments do not match

How can I track down this error? Is one of the 1000 data frames within the list not 8 columns long? Thank you for any help.

Here is one of the data frames in the list:

> b6000[["7311 USA"]]
      from        to       m       km    miles seconds  minutes    hours
1 7311 USA 19111 USA 1580725 1580.725 982.2625   55211 920.1833 15.33639
> 
John U
  • 35
  • 5
  • 4
    It simply means that number of columns vary in you data frames. Check the dimension of all the data frames by `lapply(dfs, dim)` and figure out. – Agaz Wani Mar 17 '18 at 14:02
  • Or to get exactly the one `which(lapply(dfs, function(x) which(ncol(x) != 8)) == 1)` – Agaz Wani Mar 17 '18 at 14:06
  • Thank you. I did that and noticed that some were 1x6 instead of 1x8. – John U Mar 17 '18 at 14:07
  • 1
    you could also use the rbindlist function from the data.table package, which has a fill argument that will allow this operation to work. you'll have to examine the output then to determine whether or not filling was erroneous. if the columns in your list are named, you can use the use.names argument to help ensure accuracy. – MichaelChirico Mar 17 '18 at 14:16
  • rbindlist worked well with the fill argument. That's what was needed. – John U Mar 17 '18 at 17:21

0 Answers0