title: Why does extracting a date from a dataframe work when its outside of a function, but not when it is used inside a function? R
body: <p>I'm new to coding in general, and have a feeling that this problem is more a structural thing than a syntax thing.</p>
  <p>I have the following dataframe:</p>
  <pre><code>mm &lt;- c(0,0,1,30,0,50)
  dates &lt;- as.Date(c(&quot;2020-06-01&quot;, &quot;2020-06-02&quot;, &quot;2020-06-03&quot;, &quot;2020-06-04&quot;, &quot;2020-06-05&quot;, &quot;2020-06-06&quot;))
  weather &lt;- data.frame(dates, mm)
  </code></pre>
  <p>I want to create a function and loop to concatenate a string and a date if the mm of rain is 35 or more for the given date.</p>
  <pre><code>testfunction &lt;- function() {
    if(i &gt;= 35) {
      print(paste(c(
        &quot;here's the date:&quot;, 
        weather$dates[weather$mm&gt;=35]),
        sep = &quot; &quot;))
    }}
  
  for (i in weather$mm) {
    testfunction()}
  </code></pre>
  <p>Now, if I run the date extraction line outside of the function by itself:</p>
  <pre><code> weather$dates[weather$mm&gt;=35]
  
  &gt; &quot;2020-06-06&quot;
  </code></pre>
  <p>But when I run it through the function within the loop:</p>
  <pre><code>&gt; &quot;here's the date:&quot; &quot;18419&quot;  
  </code></pre>
  <p>Ignoring the expected string output, why is the date extraction not returning the same thing as outside the function?</p>