[R] Converting date vector into a serial date number

Tunga Kantarcı
Tue, 04 Apr 2017 13:51:05 -0000

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.