【问题标题】:How do I convert an R list to the equivalent Rpy2 object?如何将 R 列表转换为等效的 Rpy2 对象?
【发布时间】:2015-10-23 13:35:20
【问题描述】:

我有一个 R 对象定义为

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

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

【问题讨论】:

  • 传递给什么?你的问题描述不清楚。您可能需要多写几行来准确说明您想在这里做什么。
  • 抱歉不清楚。我的问题是将上面的行翻译成 Rpy2 中的正确行。我似乎无法在文档中找到任何列表向量对象。

标签: python r rpy2


【解决方案1】:
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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-05-31
    • 2012-10-30
    • 2020-09-19
    • 2018-12-08
    • 2011-03-06
    • 2011-01-27
    • 2014-05-17
    • 1970-01-01
    相关资源
    最近更新 更多