小编Chr*_*rek的帖子

在rpy2> = 3.0.0中,有没有办法从R向量,矩阵等返回名称

我想从命名的R向量(或矩阵等)中获取名称,再返回到Python中。在rpy2 <3.0.0中,这是可能的,例如,

>>> stats.quantile(numpy.array([1,2,3,4]))
R object with classes: ('numeric',) mapped to:
<FloatVector - Python:0x7f3e664d6d88 / R:0x55c939a540c8>
[1.000000, 1.750000, 2.500000, 3.250000, 4.000000]
>>> stats.quantile(numpy.array([1,2,3,4])).names
R object with classes: ('character',) mapped to:
<StrVector - Python:0x7f3e66510788 / R:0x55c939a53648>
['0%', '25%', '50%', '75%', '100%']
>>> stats.quantile(numpy.array([1,2,3,4])).rx('25%')
R object with classes: ('numeric',) mapped to:
<FloatVector - Python:0x7f3e68770bc8 / R:0x55c938f23ba8>
[1.750000]
Run Code Online (Sandbox Code Playgroud)

但是在rpy2> = 3.0.0中,输出将转换为numpy数组,因此当然没有.names或.rx,因此名称似乎丢失了。

>>> stats.quantile(numpy.array([1,2,3,4]))
array([1.  , 1.75, 2.5 , 3.25, 4.  ])
Run Code Online (Sandbox Code Playgroud)

rpy2 python-3.x

5
推荐指数
1
解决办法
86
查看次数

标签 统计

python-3.x ×1

rpy2 ×1