Try this: patt <- "\\d{4}[-/]\\d{2}[-/]\\d{2}" # could be \\d{2}[-/]\\d{2}[-/]\\d{4}, etc...
idx <- colSums(sapply(myData, regexpr, pattern = patt)) > 0 myData[idx] <- lapply(myData[idx], as.Date) On Fri, Apr 16, 2010 at 4:57 PM, Jeroen Ooms <jeroeno...@gmail.com> wrote: > > Yes I know I can manually do it, but I am using it for scripts in which users > upload files. Hence, I don't know what's going to come; I don't know on > before hand whether data will contain Dates, and in which columns they > appear. This is why I was surprised that read.table has some (undocumented) > behavior of converting columns that look like Dates to a different format. > > I would like to control this default behavior of the read.table function, > rather than set a type for a specific column of a specific file. > > > -- > View this message in context: > http://n4.nabble.com/read-table-behavior-for-Dates-tp2013442p2013489.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.