Rpy2:将语句从R转换为Python

时间:2019-05-13 11:59:29

标签: python r rpy2

我想转换此R代码:

spec <- CreateSpec(variance.spec = list(model = c("sGARCH","gjrGARCH")),
                   distribution.spec = list(distribution = c("std","norm")))

我在Python中尝试过:

spec = ms.CreateSpec(variance_spec = ro.ListVector({'model': 'gjrGARCH', 'model': 'sGARCH'})
                 ,distribution_spec = ro.ListVector({'distribution': 'norm', 'distribution': 'std'})

此代码在python下运行正常。但是我意识到它只考虑了dict的第二个值(“ sGARCH”代表variance_spec,“ std”代表distribution_spec)。你能帮忙吗?

编辑: 答案是:

spec = ms.CreateSpec(#variance_spec = ro.ListVector(ro.StrVector(['gjrGARCH', 'sGARCH']))
                  variance_spec = ro.ListVector({'model': ro.StrVector(('gjrGARCH', 'sGARCH'))})
                 ,distribution_spec = ro.ListVector({'distribution': ro.StrVector(('norm', 'std'))}))

0 个答案:

没有答案