Friday, January 22, 2010

Link Python with R

Took a lot of time, finally I got it.
But still some problems, for example, only wilcoxon rank sum test is there, others are missing. I'm not clear the reason. please see how to do that.

(1) download Python 2.6 and R 2.10.0
http://www.python.org/
http://www.r-project.org/
(2) download numpy and win32
http://starship.python.net/crew/mhammond/win32/Downloads.html
http://numpy.scipy.org/
(3) download Rpy
http://pypi.python.org/pypi/rpy2/
(4) install all of above
(5) set path to R.exe location, for example, C:\Program Files\R\R-2.10.1\bin
Put C:\Program Files\R\R-2.10.1\bin as Path in Environmental variable.
Like this: my computer -> property-> Advanced -> Environmental variable -> systems variable -> PATH -> Edit
(7) Open python GUI
(8) Run followings:
>>>import rpy2.robjects as robjects
>>> pi = robjects.r['pi']
>>> pi[0]
3.14159265358979

For more commands, please refer to
http://rpy.sourceforge.net/rpy2/doc-2.1/html/introduction.html#getting-started

No comments:

Post a Comment