0

I have a list of dataframes, myfiles all of which have the same first column name wc_Monday I wish to merge into a single dataframe, the name of the first column for all dataframes is the same, I cannot find a way to do this, so far I have tried:

 do.call(merge(by="wc_Monday"),myfiles)

but this returns error

Error in as.data.frame(x) : argument "x" is missing, with no default

and

lapply(myfiles, function(x,y) merge(x,y,by.x="wc_Monday",by.y="wc_Monday",all=FALSE))

however this is giving error:

Error in as.data.frame(y) : argument "y" is missing, with no default

and

merged.data.frame = Reduce(function(...) merge(..., all=F), myfiles)

However this is producing a dataframe much longer than the sum of all the dataframes.

Any help on why these won't work greatly appreciated.

user124123
  • 1,642
  • 7
  • 30
  • 50
  • 1
    new.df<-data.frame(join.all(myfiles,by=wc_Monday)) You'll need library(plyr) – Matias Andina Jul 22 '15 at 12:55
  • hi @MatiasAndina is there a way to specify the all option on this function? – user124123 Jul 22 '15 at 13:05
  • or use `Reduce()` ... – Ben Bolker Jul 22 '15 at 13:06
  • @user1987097 I don't understand the "all" option. what are you trying to do? – Matias Andina Jul 22 '15 at 13:07
  • Hi @BenBolker I tried reduce but it produced far too large a dataframe. – user124123 Jul 22 '15 at 13:13
  • @user1987097 try specifiing the column name using which you want to `merge` inside `Reduce` like this `Reduce(function(...) merge(..., by = "wc_Monday"), myfiles)`. Also there is no need to specify `all = F` because it is set to false by default – Veerendra Gadekar Jul 22 '15 at 13:15
  • @VeerendraGadekar this produced the same error as my first attempt without the column name. – user124123 Jul 22 '15 at 13:23
  • 1
    @user1987097 it would help if you can post a sample data and mimic the error which you are facing, you could also try using `left_join` of dplyr check [here](http://stackoverflow.com/questions/31480615/data-table-left-outer-join-on-multiple-tables/31481121#31481121), Also the link mentioned as duplicate is very useful – Veerendra Gadekar Jul 22 '15 at 13:29
  • @VeerendraGadekar So my desired final dataset was 200 rows long, each element of the list was no more than 300 rows long, but the table produced by Reduce in the call detailed above was tens of thousands of rows long. – user124123 Jul 23 '15 at 10:19
  • @user1987097 could you upload the `dput` of your dataset with 200 rows? or like i said if you can create a dummy dataset similar to yours and upload, it will be easier to sort out the problem – Veerendra Gadekar Jul 23 '15 at 14:25

0 Answers0