title: time series function not working due to possible indexing error?
body: <p>I am working with a folder of CSV files that will be analyzed via time-series. In order to perform the tests, I have decided to create a couple of functions that will pass through a for-loop to create a time-series analysis on specific variables in each file in the path.</p>
  <p>Below my code can be separated into three sections: <em>the data import, the function creation, and it passing through the for-loop</em>.</p>
  <p>The problem I am having is that I believe my function is improperly coded. When I run my code and initialize my time series function, I get an error saying the following: <code>'ts' object must have one or more observations</code>. When I try to plot my <code>data_frame</code> or the specific count of <code>csv_data</code>, the only option I have is to plot <code>csv_data$file_name</code>. This is a problem because I should get the option of <code>csv_data$placeholderName</code> instead.</p>
  <p>IS there a problem with the way I have written my function? If so, how can I fix it? Are there any other problems you can see with my code?</p>
  <p><em>NOTE: many time-series objects will be made using this same method as to make it easier to analyze multiple files. For example, using the example data below, the function will create time-series objects using the 5 placeholderName variables.</em></p>
  <p><strong>CODE:</strong></p>
  <pre class="lang-r prettyprint-override"><code># retrieve data from the csv files from PATH
  data &lt;- list.files(&quot;/path of 1160 csv files&quot;, pattern = &quot;.csv&quot;, all.files = TRUE, full.names = TRUE)
  
  # get list element for data
  csv_data &lt;- lapply(data, read.csv)
  
  # Set the name of each list element to its respective file name.
  # NOTE: full.names = FALSE to get only the file names, not the full path.
  names(csv_data) &lt;- gsub(&quot;.csv&quot;,&quot;&quot;, list.files(&quot;/path of 1160 csv files&quot;, pattern = &quot;.csv&quot;, all.files = TRUE, full.names = FALSE), fixed = TRUE)
  names(csv_data) &lt;- gsub(&quot;, &quot;, &quot;-&quot;, names(csv_data), fixed = TRUE)
  
  # Determine the amount of csvs in path
  csv_length &lt;- as.integer(length(csv_data))
  
  # placeholderName is converted into time-series data. 
  # Since dates were not mentioned in the Date format (shown as string)
  # Thus general index were used (1 to 248)
  # Declaring time series object
  
  count &lt;- 0
  timeSeries &lt;- function(count) {
    data_frame &lt;- csv_data[count]
    data_frame[is.na(data_frame)] = 0
    placeholderName_ts = ts(data_frame$placeholderName, start = 1, end=248, frequency = 1)
    return(placeholderName_ts)
  }
  
  for (i in 1:csv_length) {
    count = i
  
    # time series creation
    timeSeries(i)
  }
  </code></pre>
  <p><strong>EXAMPLE DATA:</strong></p>
  <pre><code># placeholderName = phN
  $`File-name-1`
         date            phN1   phN2      phN3     phN4         phN5
  1   2020-02-15          0  8.331944  1.8722222 65.29108        NA
  2   2020-02-16          1 15.045833 11.9569444 83.02963        NA
  3   2020-02-17          1 15.090278 14.2013889 94.59667        NA
  4   2020-02-18          5 20.806944 19.0736111 90.42332        NA
  5   2020-02-19          1 13.134722 11.9388889 92.53200        NA
  6   2020-02-20          0  9.240278  8.0916667 92.64821        NA
  7   2020-02-21          2  5.838889 -0.8875000 64.58893        NA
  </code></pre>
  <p>Any more information, when requested will be added below:</p>
  <ul>
  <li>Edit_1: Each file (dataset) has the same structure: date, phN1, phN2, phN3, phN4, and phN5.</li>
  </ul>