[R] Converting date vector into a serial date number

Bert Gunter bgunter.4567 at gmail.com
Tue Apr 4 16:55:46 CEST 2017

?strptime  and ?paste (to combine your 2 date vector pieces)


Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )

On Tue, Apr 4, 2017 at 6:51 AM, Tunga Kantarcı <tungakantarci at gmail.com> wrote:
> I have a data frame. One column (call this column a) contains years,
> like 1871, and another column (call this column b) contains months,
> like 2. I need to convert these year-month combinations, stored in
> these two date vectors, into a single serial date number. E.g. year
> 1871 and month 2, stored in different vectors, should return 683429.
> Meanwhile, when I check the class type of columns a and b, they are
> both integer.
> In MATLAB this can easily be done using the syntax
> output = datenum(a,b,1)
> In R, I have tried the as.POSIXct function but did not succeed. I also
> tried the ISOdatetime function but that returned NA for all entries.
> It should be a simple operation but I cannot seem to figure it out.
> ______________________________________________
> 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.

More information about the R-help mailing list