title: merging multiple csv's in R
body: <p>Hi i was merging csv downloaded from NSE Bhavcopy. different dates have different no of cols. Say in 26-12-2006 it had 998 rows &amp; 27-12-2006 it has 1003 rows. It has 8 cols. I do the cbind to create a &amp; b with just 2 cols, Symbol, close price. I name the col using colnames so that for merging i can merge by SYMBOL. </p>
  
  <p>Questions:</p>
  
  <p>1) When i use merge function with by = "SYMBOL", all = F; i was surprised to see resulting c having 1011 rows. where ever i read, merging with all = F it should become 998 rows or max 1003 rows. I also analyzed the data and found there were 5 different symbols in 27-12-2006 &amp; 3 different symbols in 26-12-2006. So when we merge by "SYMBOL" will new symbols from both rows will be added? or it will merge only with earlier existing a row?</p>
  
  <p>2) NSEmerg is a function using a for loop to read new file every time &amp; merge with existing c file. I have about 1535 files having data from 2006 Dec till 2013 Apr. However i was not able to merge more than 12 files as it throws error vector size of 12 MB cannot be allowed. It also shows warning messages saying memory allocation of 1535 MB used up. Also at 12th file i found nrow of c to be 1508095 implying loop running infinitely. Of all the 1535 files, highest row was at 1435. Even if we add all stocks delisted, no traded on specific date, i believe it might not cross 2200 stocks. Why this shows nrow of 1.5 Million??</p>
  
  <p>3) Is there any better way of merging csv? I am in stack overflow for first time else i would have attached say 10 files.</p>
  
  <p>Code:</p>
  
  <pre><code>a &lt;- read.csv("C://Users/home/desktop/061226.csv", stringsAsFactors = F, header = T)
  b &lt;- read.csv("C://Users/home/desktop/061227.csv", stringsAsFactors = F, header = T)
  a_date &lt;- a[2,1]
  b_date &lt;- b[2,1]
  a &lt;- cbind(a[,2],a[,6])
  b &lt;- cbind(b[,2], b[,6])
  colnames(a) &lt;- c("SYMBOL", a_date)
  colnames(b) &lt;- c("SYMBOL", b_date)
  c &lt;- merge(a,b,by = "SYMBOL", all = F)
  
  NSEmerg &lt;- function(x,y) {
       y_date &lt;- y[2,1]
       y &lt;- cbind(y[,2], y[,6])
       colnames(y) &lt;- c("SYMBOL", y_date)
       c &lt;- merge(c, y, by = "SYMBOL", all = F)
     }
  
  filenames = list.files(path = "C:/Users/home/Documents/Rest data", pattern = "*csv")
  
  for (i in 1:length(filenames)){
      y &lt;- read.csv(filenames[i], header = T, stringsAsFactors = F)
      c &lt;- NSEmerg(c,y)
     }
  
  write.csv(c, file = "NSE.csv")
  </code></pre>