2

I'm calling a function in R through RDotNet library (.NET c#). When calling through R itself the output is a dataframe where one of the columns are Dates with "Date" format. But when calling the function with RDotNet and reading it as DataFrame (AsDataFrame()) the return type of the "Date" column is a NumericVector. What am I doing wrong?
How can I convert that numericvector into a DateTime format in c#? Or just how can I read a Date type format from a dataframe outputed from an R script in c#?

Example of the evaluation in c#:

res = engine.Evaluate($@"variable <- function())").AsDataFrame();
res["enter_day"][1] (type is an int and not Date). 

Example of one of the numericvectors: 17655.

Example of the output in RStudio (R):

Example

It is a dataframe and one of the columns is the one showed in the img.

Thanks in advance!

miselking
  • 3,043
  • 4
  • 28
  • 39
João Mota
  • 21
  • 3

1 Answers1

0

You have to use DateTime.FromOADate. In F#:

open System

let RDateOffset = 25569.
let toRDate (d : DateTime) = d.ToOADate() - RDateOffset
let fromRDate d = DateTime.FromOADate(d + RDateOffset)

(fromRDate 17655.).ToString("yyyy-MM-dd") //output: "2018-05-04"
FRocha
  • 942
  • 7
  • 11