[R] Converting date vector into a serial date number

Bert Gunter
Tue, 04 Apr 2017 14:55:46 -0000

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

Cheers,

Bert
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.