您可以遍历Deedle(如果不包含选项值):let someFoos' = [{Which = "that"; Qty = 4.0}; {Which = "other"; Qty = 2.0}]let df' = someFoos' |> Frame.ofRecordsdf' |> R.data_frameIt seems like the RTypeProvider can only handle namedParams of the same type. Is this the case?For example, open RDotNetopen RProvidertype foo = { Which: string Qty: float option }let someFoos = [{Which = "that"; Qty = Some 4.0}; {Which = "other"; Qty = Some 2.0}]let thingForR = namedParams [ "which", someFoos |> List.map (fun x -> x.Which); "qty", someFoos |> List.map (fun x -> x.Qty); ] |> R.data_framedoesn't work as I get an error on the x.Qty saying This expression was expected to have type stringbut here has type float optionIf I reverse the order in the thingForR let, then I get the opposite error:let thingForR = namedParams [ "qty", someFoos |> List.map (fun x -> x.Qty); "which", someFoos |> List.map (fun x -> x.Which); ] |> R.data_frameHere, the error on x.Which is This expression was expected to have type float optionbut here has type stringCan the dictionary in the namedParams not have different types? If so, how can you create a data frame with different types in F# and pass them to R? 解决方案 You need to box the values inside the dictionary. That way they are all just object. So:let thingForR = namedParams [ "which", box (someFoos |> List.map (fun x -> x.Which) ); "qty", box (someFoos |> List.map (fun x -> x.Qty) |> List.map (Option.toNullable >> float)); ] |> R.data_framegives me:Please refer to your previous question on float option to convert the Option list to float list. Also string option if necessary.You can go through Deedle (if not for the option values):let someFoos' = [{Which = "that"; Qty = 4.0}; {Which = "other"; Qty = 2.0}]let df' = someFoos' |> Frame.ofRecordsdf' |> R.data_frame 这篇关于如何使用RTypeProvider创建多种类型的数据框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-06 02:08