title: R: Convert date column of data table
body: <p>I have a CSV table that includes a date column containing different formatted date strings. I'll want to write a small function that tries to convert those strings into date objects. The idea is to try different date formats until the date can be parsed:</p>
  
  <pre><code>parseDate &lt;- function(date){
    formats &lt;- c("%d.%m.%y %H:%M", "%Y-%m-%d %H:%M:%S", "%m-%d-%Y-%H:%M:%S")
  
    for(format in formats){
      newDate &lt;- strptime(date, format=format)
      if(!is.na(newDate)){
        return(newDate)
      }
    }
  
    print(paste0("Invalid input: ", date))
    return(NA)
  }
  
  column1 &lt;- c("2014-11-14 14:20:16", "24.11.14 9:48", "24.11.14 9:49")
  table &lt;- data.frame(column1)
  
  table$column1 = lapply(table$column1, FUN = parseDate)
  </code></pre>
  
  <p>The problem is that I can't find the correct way to apply this function to the column. I tried <code>lapply</code>, <code>apply</code> and <code>by</code>, and non of those functions delivers the desired output. Could you help me here?</p>