After the morning R session at the NERRA meeting, I put some Googling time into finding out how to tell R how to handle date/time columns when reading from a file. It turns out to be relatively straight forward, here is a quick snippet:
#Here we create our own Date type, SWMPRDate and define the function
#to handle it.
setAs("character","SWMPRDate", function(from) strptime(from, format="%m/%d/%Y") )
#Here we call the read.csv, but with some extra parameters, namely the #colClasses. colClasses is where we specify the data type of each column.
#Take note the SWMPRDate column type. When R encounters it, it will use
#the function defined for is.
WQBData <- read.csv("data_WQBCR.csv",
header=TRUE,
sep=",",
colClasses=c("SWMPRDate",
"numeric", "numeric","numeric","numeric","numeric","numeric"
))
Let's say we had a date time since the sites sample at 15 minute intervals. We could define a type as so:
setAs("character","SWMPRDateTime", function(from) strptime(from, format="%m/%d/%Y %H:%M:%S") )
You need to verify what format the date/time data you are working with. In my examples above I used the sample that the example data files were in which is a month/day/4 digit Year.
The "%" directive definitions for the strptime function can be found
here
Dan