title: Merging .csv files with R
body: <p>I have 3 files with 3 variables: date, ID, and price. I would like to merge them by date, so if one my current files is:</p>
  
  <pre><code>date      ID  Price
  01/01/10   A   1
  01/02/10   A   1.02
  01/02/10   A   0.99
  ...
  ...
  </code></pre>
  
  <p>I would like to get a merged file that looks like the one below for IDs A,B and C (Pr for Price):</p>
  
  <pre><code>date       Pr.A   Pr.B  Pr.C     
  01/01/10   1      NA    NA
  01/02/10   1.02   1.2   NA
  01/03/10   0.99   1.3   1
  01/04/10   NA     1.23  2
  01/05/10   NA     NA    3
  </code></pre>
  
  <p>Notice that for some dates there are not prices so in that case is an NA.</p>
  
  <p>My current approach works but I feel is a bit clumsy.</p>
  
  <pre><code>setwd('~where you put the files')
  library(plyr)
  listnames = list.files(pattern='.csv')
  pp1 = ldply(listnames,read.csv,header=T) #put all the files in a data.frame
  
  names(pp1)=c('date','ID','price')
  pp1$date = as.Date(pp1$date,format='%m/%d/%Y')
  
  # Reshape data frame so it gets organized by date
  pp1=reshape(pp1,timevar='ID',idvar='date',direction='wide')
  </code></pre>
  
  <p>Is there any better approach you could think of?  </p>