I am new to R and am trying to import a text file that contains
date/time and various fields. I want to sort this matrix by date and
also perform calculations on the date field (difference between two
dates etc).
The format of the string looks as follows:
x<-c("25/2/2003 0:00:00")
I tried:
as.Date(x,format='%d/%m/%y')
[1] "2020-02-25"
Obviously I am doing something wrong here. I would like to remove the
hh:mm:ss from the end of the string if possible.
Thanks for your help, I have been searching for hours and not getting anywhere.
Convert date/time string to date
3 messages · Heston Capital, Brian Ripley, Gabor Grothendieck
On Sun, 11 Jan 2009, Heston Capital wrote:
I am new to R and am trying to import a text file that contains
date/time and various fields. I want to sort this matrix by date and
also perform calculations on the date field (difference between two
dates etc).
The format of the string looks as follows:
x<-c("25/2/2003 0:00:00")
I tried:
as.Date(x,format='%d/%m/%y')
[1] "2020-02-25"
Obviously I am doing something wrong here. I would like to remove the
You have a 4-figure date, so need %Y not %y. See ?strptime.
hh:mm:ss from the end of the string if possible. Thanks for your help, I have been searching for hours and not getting anywhere.
______________________________________________ R-help at 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.
Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
If the file represents a time series then you might want to look at the zoo package. See read.zoo, in particular and ?strptime and R News 4/1 for the % codes and other date/time info. Also ?lag.zoo On Sun, Jan 11, 2009 at 12:22 AM, Heston Capital
<hestoncapital at gmail.com> wrote:
I am new to R and am trying to import a text file that contains
date/time and various fields. I want to sort this matrix by date and
also perform calculations on the date field (difference between two
dates etc).
The format of the string looks as follows:
x<-c("25/2/2003 0:00:00")
I tried:
as.Date(x,format='%d/%m/%y')
[1] "2020-02-25"
Obviously I am doing something wrong here. I would like to remove the
hh:mm:ss from the end of the string if possible.
Thanks for your help, I have been searching for hours and not getting anywhere.
______________________________________________ R-help at 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.