【问题标题】:rpy2: Reading a file to a Float Vectorrpy2:将文件读取到浮点向量
【发布时间】:2018-06-12 07:23:53
【问题描述】:

我有一个简单的文件:

1 2 4 5 ...

在 R 中我可以将文件读取到向量中:

data = read.table (file_name, header = FALSE)

我想对rpy2做类似的事情:

import rpy2.robjects as ro

in_data = ro.FloatVector()
in_data.from_csvfile (path = in_file, header = False)

但我在in_data = ro.FloatVector() 行有一个错误。错误是TypeError: __init__() missing 1 required positional argument: 'obj'

我不知道应该将什么类型的obj 传递给函数。

感谢您的帮助。

【问题讨论】:

    标签: r python-3.x rpy2


    【解决方案1】:

    正如错误消息所指出的那样FloatVector 需要一个参数(参见https://rpy2.github.io/doc/v2.9.x/html/vector.html#rpy2.robjects.vectors.FloatVector)。

    文档中也有关于创建 R 向量的简短介绍:https://rpy2.github.io/doc/v2.9.x/html/introduction.html#creating-rpy2-vectors

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-03
      相关资源
      最近更新 更多