title: Applying a function to all elements of a list to create new columns
body: <p>I have the following function:</p>
  <pre><code>get_ym = function(x) {
     paste0(str_replace(str_sub(deparse(substitute(x)), start= -11, end = -5), &quot;[.]&quot;,&quot;-&quot;), &quot;-01&quot;)
  }
  </code></pre>
  <p>When applied to a single object, it works fine, like here:</p>
  <pre><code>get_ym(device.2019.01.csv)
  [1] &quot;2019-01-01&quot;
  </code></pre>
  <p>I want to apply this function to a list of objects which are essentially the same, but with different dates, like device.2019.02.csv, device.2020.03.csv, and so.</p>
  <p>When I use lapply, the output is not what I want.</p>
  <pre><code>lapply(device_files, get_ym)
  [[1]]
  [1] &quot;X[-01&quot;
  
  [[2]]
  [1] &quot;X[-01&quot;
  </code></pre>
  <p>and so on.</p>
  <p>Furthermore, I'd like to create new columns in all objects from the list using the get_ym function. So I wrote</p>
  <pre><code>apply_ym = function(x) {
    x$month = get_ym(x)
  }
  apply_ym(device.2020.03.csv)
  </code></pre>
  <p>But this doesn't work on a single object, not to mention when applied to a list.</p>
  <p>What am I doing wrong?</p>
  <p>EDIT</p>
  <p>device_files are a list of objects created like so:</p>
  <pre><code>device_files = list.files(pattern = &quot;^device.2&quot;)
  device_files = strsplit(device_files, split = &quot; &quot;)
  </code></pre>