如何将R列表转换为等效的Rpy2对象?

时间:2015-10-23 13:35:21

标签: python r rpy2

我有一个R对象定义为

seasonal = list(order = c(0, 0, 0), period = scalar)

我需要在等效对象中转换为在Rpy2中传递。请帮忙。

1 个答案:

答案 0 :(得分:0)

from rpy2.robjects.vectors import ListVector, IntVector
# if the order of the element does not matter
seasonal = ListVector({'order': IntVector((0,0,0)), 'period': scalar})
# if the order matters
seasonal = ListVector([('order', IntVector([0,0,0])),
                       ('period', scalar)])

文档中至少提到ListVectorhttp://rpy2.readthedocs.org/en/version_2.7.x/vector.html?highlight=listvector#assigning-python-style