Skip to content

Instantly share code, notes, and snippets.

@mathias-brandewinder
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mathias-brandewinder/9919522 to your computer and use it in GitHub Desktop.
Save mathias-brandewinder/9919522 to your computer and use it in GitHub Desktop.
#r @"Deedle.0.9.12\lib\net40\Deedle.dll"
#r @"Deedle.RPlugin.0.9.12\lib\net40\Deedle.RProvider.Plugin.dll"
open Deedle
open Deedle.RPlugin
let codesSeries =
Series(
countries |> Seq.map (fun c -> c.Code) |> Seq.toList,
countries |> Seq.map (fun c -> c.Code) |> Seq.toList)
let pop2010Series =
Series(
countries |> Seq.map (fun c -> c.Code) |> Seq.toList,
countries |> Seq.map (fun c -> c.Indicators.``Population (Total)``.[2010]) |> Seq.toList)
let pop2000Series =
Series(
countries |> Seq.map (fun c -> c.Code) |> Seq.toList,
countries |> Seq.map (fun c -> c.Indicators.``Population (Total)``.[2000]) |> Seq.toList)
let deedleFrame = Frame(["Codes"; "Pop 2000"; "Pop 2010" ], [ codesSeries; pop2000Series; pop2010Series])
let rFrame = R.as_data_frame(deedleFrame)
rFrame.Print()
@tpetricek
Copy link

The issue is that the last release does not handle spaces in column names. So using Pop2010 and Pop2000 will make it work.

Also, the Series and Frame constructors are maybe not the best way to create them. I much prefer using series and frame functions:

let pop2010Series = 
  series [ for c in countries -> c.Code => c.Indicators.``Population (Total)``.[2010] ]
let pop2000Series = 
  series [ for c in countries -> c.Code => c.Indicators.``Population (Total)``.[2000] ]
let deedleFrame = frame [ "Pop2000" => pop2000Series; "Pop2010" => pop2010Series ]

deedleFrame?Codes <- deedleFrame.RowKeys
let rFrame = R.as_data_frame(deedleFrame) 
rFrame.Print()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment