[R] convert number back to point separated date

peter dalgaard pdalgd at gmail.com
Mon Feb 23 15:37:04 CET 2015


On 23 Feb 2015, at 15:06 , Alain D. <dialvac-r at yahoo.de> wrote:

> Dear R-List
> 
> I have a date column formatted dd.mm.yyyy separated by points that was converted
> into a number using as.integer(date). Now I wish to convert the number back into
> the original date. Something like:
> 
> date<-as.factor(c("07.12.2010","29.04.2013"))
> 
> dd<-as.integer(date)
> 
> as.Date(dd, origin="%d.%m.%Y")# does not work
> 
> Is there a way to convert "dd" back to "date"?

> dd
[1] 1 2

So, not without referring to the value of `date`, at the very least its factor levels.

> as.Date(levels(date)[dd], format="%d.%m.%Y")
[1] "2010-12-07" "2013-04-29"

which is really not different from 

> as.Date(date, format="%d.%m.%Y")
[1] "2010-12-07" "2013-04-29"


> 
> Thank you for help!
> 
> Best wishes
> 
> Alain
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



More information about the R-help mailing list