传递seq< float选项>从F#到RProvider [英] Passing a seq<float option> from F# to RProvider
问题描述
我希望能够将option float
的序列传递给F#
中的RProvider.如果我有一个带有Some float
和None
的浮点数序列,如何使用RProvider
将None
值放入R
?我本来希望None
等同于R
中的NA
值,但我无法将seq<option float>
传递给R.
I want to be able to pass a sequence of option float
to the RProvider in F#
. If I have a sequence of floats with Some float
and None
, how can I get the None
values into R
with the RProvider
? I would have expected the None
s would be equivalent to an NA
value in R
, but I can't get pass a seq<option float>
to R.
例如,使用
open System
open RDotNet
open RProvider
open RProvider.graphics
open RProvider.stats
let optData4 =
seq [Some 10.0; Some 9.0; Some 8.0; None; Some 6.0;
Some 5.0; Some 5.0; None; Some 4.0; Some 2.0;
None]
let testData4 =
namedParams [
"regPrice", optData4;]
|> R.data_frame
我遇到多行错误:
System.Exception: No converter registered for type Microsoft.FSharp.Collections.FSharpList`1[[Microsoft.FSharp.Core.FSharpOption`1[[System.Double, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], FSharp.Core, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]] or any of its base types
> at RProvider.RInteropInternal.convertToR@164.Invoke(String message) in C:\Tomas\Public\bmc\FSharp.RProvider\src\RProvider\RInterop.fs:line 164
at RProvider.RInteropInternal.REngine.SetValue(REngine this, Object value, FSharpOption`1 symbolName) in C:\Tomas\Public\bmc\FSharp.RProvider\src\RProvider\RInterop.fs:line 274
at RProvider.RInteropInternal.toR(Object value) in C:\Tomas\Public\bmc\FSharp.RProvider\src\RProvider\RInterop.fs:line 287
at RProvider.RInterop.passArg@447(List`1 tempSymbols, Object arg) in C:\Tomas\Public\bmc\FSharp.RProvider\src\RProvider\RInterop.fs:line 461
at RProvider.RInterop.argList@468-1.GenerateNext(IEnumerable`1& next) in C:\Tomas\Public\bmc\FSharp.RProvider\src\RProvider\RInterop.fs:line 469
at Microsoft.FSharp.Core.CompilerServices.GeneratedSequenceBase`1.MoveNextImpl()
at Microsoft.FSharp.Core.CompilerServices.GeneratedSequenceBase`1.System-Collections-IEnumerator-MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at Microsoft.FSharp.Collections.SeqModule.ToArray[T](IEnumerable`1 source)
at RProvider.RInterop.callFunc(String packageName, String funcName, IEnumerable`1 argsByName, Object[] varArgs) in C:\Tomas\Public\bmc\FSharp.RProvider\src\RProvider\RInterop.fs:line 466
at <StartupCode$FSI_0012>.$FSI_0012.main@() in C:\Users\sranney\repositories\carolina_refit_bits\refit_bits\refit_bits\RDemo.fs:line 102
Stopped due to error
将任何内容传递给RProvider
的唯一方法是使用
The only way I can pass anything to the RProvider
is if I convert the seq<option float>
to a seq<float>
with
let optData4 =
seq [Some 10.0; Some 9.0; Some 8.0; None; Some 6.0;
Some 5.0; Some 5.0; None; Some 4.0; Some 2.0;
None]
|> Seq.choose id
let testData4 =
namedParams [
"regPrice", optData4;]
|> R.data_frame
但是这否定了无"选项的目的(我认为这与R
的NA
值相当.
but this negates the purpose of having the option of None (which, I would have thought would be comparable to R
s NA
value.
如何将值序列传递给RProvider
,其中某些值在F#
中为None
,而在R
中应为NA
?
How can I pass a sequence of values to the RProvider
where some of the values are None
in F#
and should be NA
in R
?
推荐答案
我认为您只需用nan
替换None
值就能做到这一点(这并不完全正确,因为在R NaN
是不同的,但是无法表达F#中的浮点数的两个不同的非值):
I think you should be able to do this just be replacing the None
values with nan
(this is not entirely right, because in R NA
and NaN
are different, but there is no way to express two different non-values for a float in F#):
let optData4 =
[ 10.0; 9.0; 8.0; nan; 6.0; 5.0; 5.0; nan; 4.0; 2.0; nan ]
let testData4 =
namedParams [
"regPrice", optData4;]
|> R.data_frame
我还没有测试过,但是我认为这是我们内部在Deedle中所做的.
I have not tested this, but I think this is what we do in Deedle internally.
这篇关于传递seq< float选项>从F#到RProvider的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!