title: Clock with loops in R to rename time-stamped files
body: <p>I have to rename several tens of thousands of audio files of 5 seconds each, each of them coming from a file of 5 minutes (5minutes/5secondes = 60 files). To do this I need to define the time (hour, minute and second) of the beginning of the 5 minutes recording and I tried to make a clock that advances from 5 seconds to 5 seconds and that keep the values of seconds, minutes and hours in vectors to rename the files using these vectors like this:</p>
  <pre><code>stwd(&quot;&quot;)
  
  name = &quot;Car041512-2021-Pass1-Z2_20210914_211000_&quot; #file name prefix 
  
  hours = 21
  minutes = 19
  seconde = 9
  
  
  for (i in 0:59) {
    
      seconde[i+1] = secondes + i*5 
      
      
  if(seconde[i+1] &gt;= 60) 
      seconde[i+1] = seconde[i+1] - 60
      minute[i+1]= minutes+1  
  
    if (minute &gt;= 60)
      minutes = 0
      hour[i+1] = hours + 1
  }
  
  time = as.character(paste0(hour,minute,seconde))
  
  
  list =list.files(all.files=F)
  
  rename = paste0(name,time,&quot;.wav&quot;)
  
  file.rename(list, rename)
  
  </code></pre>
  <p>I have a problem at the beginning of the loop. The seconds vector does not exceed 60 seconds but only during 2 cycles and I do not see why. This is the first time I've done loops with R and I must have made a lot of mistakes.</p>
  <pre><code>seconde
   [1] 9  14  19  24  29  34  39  44  49  54  59   4   9  14  19  24  29  34  39  44  49  54  59 64  69  74  79  84  89  94 99 104 109 114 119 124 129 134 139 144 149 154 159 164 169 174 179 184 189 194 199 204 209 214 219 224 229 234 239 244
  </code></pre>
  <p>The renaming of the files works correctly, it's just the loop that doesn't work correctly. Can you help me?</p>
  <p>Thanks in advance.</p>