This project is read-only.

Passing NA and NaN values to R.NET

Nov 7, 2013 at 5:15 PM
R uses NA to represent missing values and NaN to represent not a number. Using the F# type provider for R, I can create a numeric vector that contains both of these using:
R.eval(R.parse(text="c(1,NA, NaN)"))
I would like to create a vector containing NA and NaN using the engine.CreateXyzVector operations, but I'm not sure how to do that. I can create NA for string vector and NaN for numeric vector:
engine.CreateCharacterVector [null; "hi"] // Creates vector c(NA, 'hi')
engine.CreateNumericVector [Double.NaN; 3.14] // Creates vector c(NaN, 3.14)
... but I cannot find a way to create numeric vector containing NA or integer vector containing either NaN or NA. I thought about using engine.CreateNumericVector(10) to create an empty vector, but that initializes the values to zeros...

If this is not possible in the current version of R.NET, where should I look if I wanted to add this?

Also, when I convert the vector created using c(1, NA, NaN) to .NET using AsNumeric, I get [1.0; nan; nan] and when I use AsInteger, I get [1; -2147483648; -2147483648]. Does that mean the distinction between NA and NaN gets lost?

Nov 7, 2013 at 11:55 PM
R.NET has no good way to handle such a special values. R manages such special values in some special ways.

This is reported in If you have a good solution, please let us know.