[R] Converting factor data into Date-time format
R. Michael Weylandt
michael.weylandt at gmail.com
Tue Mar 13 17:30:06 CET 2012
as.POSIXct(as.character(FACTORHERE), format = "%d/%m/%Y %H:%M")
On Tue, Mar 13, 2012 at 12:20 PM, Haojie Yan <yhj204 at googlemail.com> wrote:
> Dear R-user,
> I have read a dataset from .csv file into R. This dataset includes one
> column containing some data in 'date and time' format, e.g. 'dd/mm/yyyy
> These data were automatically read and saved as 'factor' in R. When I was
> trying to produce some plots (such as time series) with the above 'date and
> time' on x-axis, it caused some disodering problem, e.g. 1st of March 2012
> is in front of 10th of Feb. 2012 (if the data is from 10th Feb. 2012 to 1st
> of March 2012). I understand that I might have to convert them from
> 'factor' to 'date' first, so I tried using 'as.date'. But this method seems
> only work for data in format of 'd/m/y' and no further option that allows
> me to add hours and minutes.
> I checked online for other methods such as 'as.POSIX' and 'strptime' but
> none of them seem to offer me a quick solution.
> Please note that the data I received is recorded every 10 minutes so they
> are saved in the form of 'dd/mm/yyyy hh:mm', e.g. I only have data
> measured up to 'minute' NOT to 'second'. Are there any direct solution
> that I can solve this issue??
> Many thanks in advance!
> [[alternative HTML version deleted]]
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help