title: For loop in R assigning to data frame
body: <p>I am having trouble assigning to a dataframe after running the for loop. When I use print it give my value, any explanation to it?</p>
  
  <pre><code> salesdate&lt;-rep(seq(from=as.Date("2013-12-19"),to=as.Date("2013-12-23"),by=1),100)
   memberid&lt;-as.factor(sample(1:1000,500))
   msales&lt;-data.frame(salesdate,memberid)
  
   new&lt;-seq(from=as.Date("2013-12-19"),to=as.Date("2013-12-23"),by=1)
   for(i in new) 
  +   print(length(unique(msales[(msales$salesdate&gt;="2013-12-23" | msales$salesdate&gt;=i),]$memberid)))
  [1] 500
  [1] 400
  [1] 300
  [1] 200
  [1] 100
  
   test &lt;- rep(NA,length(new))
   new&lt;-seq(from=as.Date("2013-12-19"),to=as.Date("2013-12-23"),by=1)
   for(i in new) 
  +   test[1:5]&lt;-length(unique(msales[(msales$salesdate&gt;="2013-12-23" | msales$salesdate&gt;=i),]$memberid))
  &gt; test
  [1] 100 100 100 100 100
  </code></pre>
  
  <p>I created some sample. My goal is to count the number of unique id from each date period from current date. Thanks for the guide, guys.</p>