Interfacing R from Python

The rpy2 package allows to interface R from Python. The following example shows how to convert data (numpy.ndarray) to an R matrix and execute the R command summary on it.

>>> from obspy.core import read
>>> import rpy2.robjects as RO
>>> import rpy2.robjects.numpy2ri
>>> r = RO.r
>>> st = read("test/BW.BGLD..EHE.D.2008.001")
>>> M = RO.RMatrix(st[0].data)
>>> print(r.summary(M))  
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
-1056.0  -409.0  -393.0  -393.7  -378.0   233.0