Jozef Cechovsky Jozef Cechovsky - 4 months ago 19
R Question

F# R type provider and cbind

I'd like to visualize data with matplot but initially I need to combine them through

R.cbind
.

I have two quantiles arrays
quantiles1
and
quantiles2
like this

val it : double [] =
[|9.493529797e-05; 0.00356456441; 0.006148920477; 0.01201379844;
0.04056193231; 0.1144207457; 0.3402441047; 0.7572200933; 1.432890804;
2.755986279|]


When I call

R.cbind(quantiles1, quantiles2)


the result is

val it : SymbolicExpression =
...
[1,] 0.0000949353
[2,] 0.0035645644
[3,] 0.0061489205
[4,] 0.0120137984
[5,] 0.0405619323
[6,] 0.1144207457
[7,] 0.3402441047
[8,] 0.7572200933
[9,] 1.4328908043
[10,] 2.7559862789


But I'd expect two columns here.
What is the way how I should use get correct result with
cbind
in F# type provider?

Answer

This should work for you:

let x12 = R.cbind(namedParams ["x1", box x1; "x2", box x2])
R.dim(x12)
// val it : SymbolicExpression = [1] 10  2

The reason is that R.cbind expects the following type: enter image description here

Edit You can make a helper function if it gets too tedious....

let makeRParams (xs:#seq<_>) =
    xs
    |> Seq.mapi (fun i x -> ("x"+i.ToString(),box x))
    |> dict
Comments