传递seq< string option>从F#到RProvider [英] Passing a seq<string option> from F# to RProvider

查看:70
本文介绍了传递seq< string option>从F#到RProvider的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我上周问此问题关于传递给RProvider的值.我希望我能够在那里将接受的答案应用于F#中的其他option类型.不幸的是,NaN仅适用于R中的numeric.

I asked this question last week regarding seq<float option> values passed to RProvider. I had hoped that I'd be able to apply the accepted answer there to other option types in F#. Unfortunately, NaN is only applicable to numeric in R.

如何将F#中的None字符串转换为NA并传递给R?

How can I convert a None string in F# to NA and pass to R?

推荐答案

您可以使用Option.toObj.

例如:

let l1 = [ Some "x"; None; Some "y"] 

let l2 = l1 |> List.map (Option.toObj)
// val l2 : string list = ["x"; null; "y"]

并且您可以将Option.toNullable用于数字值,但是它将转换为类型Nullable<float>,而None也将是null. 由于某种原因,这反过来又行不通:

And you can use Option.toNullable for number values, but it would convert to type Nullable<float>, and None would also be null. For some reason this doesn't work the other way round:

let l3 = l2 |> List.map (Option.ofObj)
// val l3 : string option list = [Some "x"; null; Some "y"]

我不知道这是故意还是错误.

I don't know if that's intended or a bug.

Option.ofObj可以正常工作.由于某些原因,F#Interactive在列表中将None显示为null.

Edit : Option.ofObj does work properly. F# Interactive displays None as null when it is in a list for some reason.

这篇关于传递seq&lt; string option&gt;从F#到RProvider的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆