In R vectors can be named, that is elements of the vector have a name.
Assigning, R-style
The attributes rx and rx2 used previously can again be used:
For the sake of complete compatibility with R, arguments can be named (and passed as a dict or rpy2.rlike.container.TaggedList).
In S/Splus/R special NA values can be used in a data vector to indicate that fact, and rpy2.robjects makes aliases for those available as data objectsNA_Logical, NA_Real, NA_Integer, NA_Character, NA_Complex .
To expose that to Python, a delegating attribute ro is provided for vector-like objects.
R vectors can have a name given to all or some of the elements. The property names can be used to get, or set, those names.
Array
In R, arrays are simply vectors with a dimension attribute. That fact was reflected in the class hierarchy with robjects.Array inheriting from robjects.Vector.
Matrix
A Matrix is a special case of Array. As with arrays, one must remember that this is just a vector with dimension attributes (number of rows, number of columns).
DataFrame
In rpy2.robjects,DataFramerepresents the R class data.frame.
Creating a DataFrame can be done by:
The DataFrame constructor accepts either an rinterface.SexpVector (with typeof equal to VECSXP, that is, an R list) orany Python object implementing the method items()(for example dict or rpy2.rlike.container.OrdDict).
To create a DataFrame and be certain of the clumn order order, an ordered dictionary can be used:
Here again, Python’s __getitem__() will work as a Python programmer will expect it to:
The DataFrame is composed of columns, with each column being possibly of a different type:
The approach followed in rpy2 has 2 levels (rinterface and robjects), and conversion functions help moving between them.
R vectors are mapped to Python objects implementing the methods__getitem__() / __setitem__()in the sequence protocol so elements can be accessed easily.
R functions are mapped to Python objects implementing the__call__()so they can be called just as if they were functions.
R environments are mapped to Python objects implementing__getitem__() / __setitem__()in the mapping protocol so elements can be accessed similarly to in a Python dict.
In its high-level interface rpy2 is using a conversion system that has the task of convertion objects between the following 3 representations:- lower-level interface to R (rpy2.rinterface level), - higher-level interface to R (rpy2.robjects level) - other (no rpy2) representations
R vectors or arrays can be converted to numpy arrays using numpy.array() or numpy.asarray().
The activation (and deactivation) of the automatic conversion of numpy objects into rpy2 objects can be made with:
R语言:DNA序列比对后计算遗传距离(P-distance) 在R语言中找到了计算遗传距离的函数dist.dna();但是不知道在R里面如何利用循环批量处理文件计算遗传距离 。想到了利用python来调用R函数的方法,查找相关教程发现需要用到rpy2模块 。
easy_install rpy2 报错(看不懂报错内容);
pip install rpy2 报错(提示需要更新pip到pip19.0.3);
利用 python -m pip install --upgrade pip 更新pip报错(看不懂报错内容);
利用教程安装pip成功更新 。
使用 pip install rpy2 安装依旧报错(看不懂报错内容);
尝试教程安装rpy2 , 提示 rpy2-2.9.5-cp37-cp37m-win_amd64.whl is not a supported wheel on this platform
在rpy2主页发现一句话Releasend source packages are available on PyPi. Installing should be as easy *as
(*:except on Windows)
这意思是在windows系统使用pip安装不太容易吗?
找到了教程 rpy2:在python中调用R函数的一个实例 ;发现其中rpy2的安装使用的是conda,自己也尝试在windows的DOS窗口下使用 conda install rpy2 成功 。但是结尾处提示了一句 此时不应有do 不明白是什么意思
推荐阅读
- 游戏仿真模拟器封面,游戏仿真模拟器封面怎么设置
- 茂名应急管理局公众号关注,陕西应急管理局公众号
- 作文网络游戏300字,网络游戏作文200字
- 电视全面屏什么,电视全面屏的好处
- mysql多表怎么关联 mysql怎么多表联查
- jquery表格tree,jquery表格筛选
- mysql如何查询某条记录是第多少条,mysql查询每个用户的第一条记录
- 视频号投流价格怎么设置,视频号 投票
- java小闹钟代码 java闹钟小程序