In [2]:
import pandas as pd
import pandas.rpy.common as com
import rpy2
r = rpy2.robjects.r
In [2]:
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C':[7,8,9]},
                 index=["one", "two", "three"])
rdf = com.convert_to_r_dataframe(df)
In [3]:
r.assign('bob', rdf)
Out[3]:
<DataFrame - Python:0x10b9159e0 / R:0x1083aa038>
[IntVector, IntVector, IntVector]
  A: <class 'rpy2.robjects.vectors.IntVector'>
  <IntVector - Python:0x10b915d40 / R:0x1086d84e8>
[       1,        2,        3]
  B: <class 'rpy2.robjects.vectors.IntVector'>
  <IntVector - Python:0x10b915cb0 / R:0x1086d84b0>
[       4,        5,        6]
  C: <class 'rpy2.robjects.vectors.IntVector'>
  <IntVector - Python:0x10b915ef0 / R:0x1086d8478>
[       7,        8,        9]
In [9]:
%R plot(bob$$A, bob$$B)
In [5]:
r.assign('testX', df.A)
r.assign('testY', df.B)
%R plot(testX, testY)
In [6]:
%R hist(bob$$A)
Out[6]:
array([<rpy2.rinterface.SexpVector - Python:0x10acbb210 / R:0x1083c6028>,
       <rpy2.rinterface.SexpVector - Python:0x10acbb1e0 / R:0x10868d608>,
       <rpy2.rinterface.SexpVector - Python:0x10acbb240 / R:0x1085d40c8>,
       <rpy2.rinterface.SexpVector - Python:0x10acbb258 / R:0x1085d3fa8>,
       <rpy2.rinterface.SexpVector - Python:0x10acbb270 / R:0x1085d3e88>,
       <rpy2.rinterface.SexpVector - Python:0x10acbb288 / R:0x10791fca8>,
       <rpy2.rinterface.SexpVector - Python:0x10acbb2a0 / R:0x107910d48>], dtype=object)
In [7]:
%R hist(testX)
Out[7]:
array([<rpy2.rinterface.SexpVector - Python:0x10acbb318 / R:0x108020f10>,
       <rpy2.rinterface.SexpVector - Python:0x10acbb2e8 / R:0x10851c740>,
       <rpy2.rinterface.SexpVector - Python:0x10acbb348 / R:0x10860c560>,
       <rpy2.rinterface.SexpVector - Python:0x10acbb360 / R:0x10860c3b0>,
       <rpy2.rinterface.SexpVector - Python:0x10acbb378 / R:0x10860c320>,
       <rpy2.rinterface.SexpVector - Python:0x10acbb390 / R:0x108718988>,
       <rpy2.rinterface.SexpVector - Python:0x10acbb3a8 / R:0x108718958>], dtype=object)
Back to top