I am reading an apache logfile using read.table and am wondering if it’s somehow possible to apply a function (i.e. strptime ) while the data are being imported, instead of post-processing it.
More details as requested:
The column containing the date has the format:
[10/Nov/2011:06:25:14
I can successfully parse it using:
strptime(red[1,4],format="[%d/%b/%Y:%H:%M:%S")
or
as.POSIXct(strptime(red[1,4],format="[%d/%b/%Y:%H:%M:%S"))
but
as.POSIXct(red[1,4],format="[%d/%b/%Y:%H:%M:%S")
fails. Hence I cannot use POSIXct in colClasses AFAIK.
If there is an
as.method you can use colClasses with that class. Since Date is a class and has a default format of YYYY-MM-DD, if your dates are in that format, you could just include Date in thecolClassesvector. It is also possible to define newas.function‘s. As always, the more detail you supply about the problem, the better the answer.Should probably give Gabor Grothendieck some credit since he is the one who showed me how to do this 5 years ago:
https://www.stat.math.ethz.ch/pipermail/r-help/2007-April/130912.html