4

I have a python dictionary and want to import it in R.

d = {'X1':[[1,2,3], [10,20]], 'X2':[4,5,6,7]}

In "R" I want it as

> d
$X1
$X1[[1]]
[1] 1 2 3

$X1[[2]]
[1] 10 20


$X2
[1] 4 5 6 7

How can I export/save the python dictionary and read it in R?

El Developer
  • 3,300
  • 1
  • 19
  • 40
d.putto
  • 6,595
  • 10
  • 38
  • 44

2 Answers2

3
  1. Use JSON: Importing data from a JSON file into R
  2. Use RPY2: http://rpy.sourceforge.net/
  3. Use HDF Format: Does anyone have experience opening hdf files in R (Windows OS)?
Community
  • 1
  • 1
Thorsten Kranz
  • 11,837
  • 1
  • 36
  • 53
1

To read it from an R session you can save your dictionary in JSON format (maybe you will need to install an R library to decode it, like jsonlite or rjson). Otherwise, write it in a table that you can load with read.table, such as CSV format.

JulienD
  • 6,730
  • 9
  • 48
  • 77