[R] transforming dates

2019-11-04 Thread Stefano Sofia
PhD Civil Protection - Marche Region Meteo Section Snow Section Via del Colle Ameno 5 60126 Torrette di Ancona, Ancona Uff: 071 806 7743 E-mail: stefano.so...@regione.marche.it ---Oo-oO Date: Sat, 2 Nov 2019 21:25:09 -0500 From: To: Subject: [R] transforming dates Message-ID: <

Re: [R] transforming dates

2019-11-03 Thread Spencer Graves
On 2019-11-03 17:04, Peter Dalgaard wrote: On 3 Nov 2019, at 21:22 , David Winsemius wrote: On 11/3/19 11:51 AM, Bert Gunter wrote: === Hey, that's my birthday! Err, no it isn't... ;-)   Is that November 3 of 2019 or March 19 of 2011 or 11 March 2019?  [please excuse the

Re: [R] transforming dates

2019-11-03 Thread Spencer Graves
On 2019-11-03 17:04, Peter Dalgaard wrote: On 3 Nov 2019, at 21:22 , David Winsemius wrote: On 11/3/19 11:51 AM, Bert Gunter wrote: === Hey, that's my birthday! Err, no it isn't... ;-)   Is that November 11 of 2019 or March 19 of 2011 or 11 March 2019?   The English

Re: [R] transforming dates

2019-11-03 Thread Peter Dalgaard
> On 3 Nov 2019, at 21:22 , David Winsemius wrote: > > > On 11/3/19 11:51 AM, Bert Gunter wrote: === Hey, that's my birthday! Err, no it isn't... ;-) -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark

Re: [R] transforming dates

2019-11-03 Thread Bert Gunter
Yes, indeed. Thanks, David. Cheers, Bert On Sun, Nov 3, 2019 at 12:22 PM David Winsemius wrote: > > On 11/3/19 11:51 AM, Bert Gunter wrote: > > Rui is right -- lubridate functionality and robustness is better -- but > > just for fun, here is a simple function, poorly named reformat(), that >

Re: [R] transforming dates

2019-11-03 Thread David Winsemius
On 11/3/19 11:51 AM, Bert Gunter wrote: Rui is right -- lubridate functionality and robustness is better -- but just for fun, here is a simple function, poorly named reformat(), that splits up the date formats, cleans them up and standardizes them a bit, and spits them back out with a sep

Re: [R] transforming dates

2019-11-03 Thread Bert Gunter
Rui is right -- lubridate functionality and robustness is better -- but just for fun, here is a simple function, poorly named reformat(), that splits up the date formats, cleans them up and standardizes them a bit, and spits them back out with a sep character of your choice (your original split

Re: [R] transforming dates

2019-11-03 Thread Rui Barradas
Hello, I believe the simplest is to use package lubridate. Its functions try several formats until either one is right or none fits the data. x <- c('11/7/2016', '14-07-16') lubridate::dmy(x) #[1] "2016-07-11" "2016-07-14" The order dmy must be the same for all vector elements, if not y <-

Re: [R] transforming dates

2019-11-02 Thread Bert Gunter
Well, one way to do it is via regex's -- no splitting and recombining needed. Note: This will convert a factor into a character vector. > z <- c("11/7/2016", "14-07-16") > z <- gsub("-([[:digit:]]{2})-([[:digit:]]{2})", "/\\1/20\\2",z) ## /\ is / and \ > z [1] "11/7/2016" "14/07/2016" I leave

[R] transforming dates

2019-11-02 Thread reichmanj
R-Help Forum I have a data set that contains a date field but the dates are in two formats 11/7/2016dd/mm/ 14-07-16 dd-mm-yy How would I go about correcting this problem. Should I separate the dates, format them , and then recombine? Sincerely

[R] transforming dates into years

2010-08-13 Thread Dimitri Liakhovitski
Hello! If I have in my data frame MyFrame a variable saved as a Date and want to translate it into years, I currently do it like this using zoo: library(zoo) as.year - function(x) as.numeric(floor(as.yearmon(x))) myFrame$year-as.year(myFrame$date) Is there a function that would do it directly -

Re: [R] transforming dates into years

2010-08-13 Thread Henrique Dallazuanna
You've tried: as.numeric(format(Sys.Date(), '%Y')) On Fri, Aug 13, 2010 at 4:36 PM, Dimitri Liakhovitski dimitri.liakhovit...@gmail.com wrote: Hello! If I have in my data frame MyFrame a variable saved as a Date and want to translate it into years, I currently do it like this using zoo:

Re: [R] transforming dates into years

2010-08-13 Thread David Winsemius
On Aug 13, 2010, at 3:36 PM, Dimitri Liakhovitski wrote: Hello! If I have in my data frame MyFrame a variable saved as a Date and want to translate it into years, I currently do it like this using zoo: library(zoo) as.year - function(x) as.numeric(floor(as.yearmon(x)))

Re: [R] transforming dates into years

2010-08-13 Thread Saeed Abu Nimeh
myFrame$year-years(strptime(x)) On Fri, Aug 13, 2010 at 12:36 PM, Dimitri Liakhovitski dimitri.liakhovit...@gmail.com wrote: Hello! If I have in my data frame MyFrame a variable saved as a Date and want to translate it into years, I currently do it like this using zoo: library(zoo) as.year