Skip to content

Instantly share code, notes, and snippets.

@wstrinz
Created June 24, 2013 18:34
Show Gist options
  • Save wstrinz/5852333 to your computer and use it in GitHub Desktop.
Save wstrinz/5852333 to your computer and use it in GitHub Desktop.
require 'rserve'
@R = Rserve::Connection.new()
def dump_dataframe(var)
h = {}
h[var] = {"attr" => {}, "rows"=>{}}
x = @R.eval(var)
x.attr.payload.keys.map{ |a|
h[var]["attr"][a] = x.attr.payload[a].to_ruby
}
rownames = x.attr.payload["row.names"].to_ruby
colnames = x.payload.keys
rownames.each_with_index.map{ |row,i|
rh = {}
colnames.map{ |col|
rh[col] = x.payload[col].to_a[i].to_f
}
h[var]["rows"][row] = rh
}
h
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment