PythonTip >> 博文 >> 开源软件

R语言的Python调用接口 RPy

zihua 2013-09-24 22:09:39 点击: 937 | 收藏


RPy是一个非常简单、健壮的R语言的Python调用接口。

示例代码:

import rpy2.robjects as robjects

r = robjects.r

ctl = robjects.FloatVector([4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14])
trt = robjects.FloatVector([4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69])
group = r.gl(2, 10, 20, labels = ["Ctl","Trt"])
weight = ctl + trt

robjects.globalEnv["weight"] = weight
robjects.globalEnv["group"] = group
lm_D9 = r.lm("weight ~ group")
print(r.anova(lm_D9))

lm_D90 = r.lm("weight ~ group - 1")
print(r.summary(lm_D90))
原文链接:http://www.oschina.net/p/rpy

作者:zihua | 分类: 开源软件 | 标签: python开源 | 阅读: 937 | 发布于: 2013-09-24 22时 |