Message-ID: <4FA13C3F.2080000@gmail.com>
Date: 2012-05-02T13:53:03Z
From: Duncan Murdoch
Subject: factor conversion to date/time
In-Reply-To: <DUB112-W95B9DABE1E2FD619EFA25F8A2E0@phx.gbl>
On 02/05/2012 8:08 AM, marjolein post wrote:
>
>
>
> Hi, I've been trying to convert numbers from an online temperature database
> into dates and time that R recognizes. I've tried as.Date, as.POSIXlt and strptime the problem is that the database has put a T between the numbers and R will not accept any conversions. currently it sees the date as a factor with the format as 1981-01-02T08:00I would like to keep only the year and month, but my primary focus is to get R to recognize it as a date.
To stop the conversion to factors, use argument stringsAsFactors=FALSE
when you read the file, or even better, options(stringsAsFactors=FALSE)
for a global change.
To convert a string, specify the format (following the instructions in
?strptime):
x <- "1981-01-02T08:00I"
strptime(x, format="%Y-%m-%dT%H:%MI")
Duncan Murdoch