5

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,345
  • 1
  • 21
  • 40
d.putto
  • 7,185
  • 11
  • 39
  • 45

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
  • 12,492
  • 2
  • 39
  • 56
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
  • 7,102
  • 9
  • 50
  • 84