English 中文(简体)
RPy2 将数据框架转换为空间GridDataFrame
原标题:RPy2 Convert Dataframe to SpatialGridDataFrame

如何使用 R 地图工具库将数据框架转换为 SpaceGridDataFrame? 我是 Rpy2 新来的, 所以这可能是个非常基本的问题 。

The R Code is: coordinates(dataf)=~X+Y

Python :

import rpy2
import rpy2.robjects as robjects
r = robjects.r
# Create a Test Dataframe 
d = { TEST : robjects.IntVector((221,412,332)),  X : robjects.IntVector(( 25 ,  31 ,  44 )),  Y : robjects.IntVector(( 25 ,  35 ,  14 ))}
dataf = robjects.r[ data.frame ](**d)
r.library( maptools )
# Then i could not manage to write the above mentioned R-Code using the Rpy2 documentation

除了这个特殊的问题之外,我很乐意得到一些反馈,了解一个更普遍的想法:我的最终目标是利用Gstat图书馆对空间数据进行回溯式搜索。 R-script运作良好,但我想打电话给我来自Python/Arcgis的脚本。你对这个任务有什么看法? 通过 rpy2 进行回归式搜索是可能的吗?

Thanks a lot! Richard

最佳回答

在某些情况下,Rpy2仍然无法动态地(和自动地)产生智能结合。

对R代码的分析将有助于:

coordinates(dataf)=~X+Y

这一点可以更明确地表述为:

dataf <- "coordinates<-"(dataf, formula("~X+Y"))

最后一个表达式使Python/rpy2 向前冲:

from rpy2.robjects.packages import importr
sp = importr( sp ) # "coordinates<-()" is there

from rpy2.robjects import baseenv, Formula
maptools_set = baseenv.get( coordinates<- )
dataf = maptools_set(dataf, Formula(  ~ X + Y ))

要( 明智地) 明确“ 坐标 & lt; - ” 的来源, 使用 :

maptools_set = getattr(sp,  coordinates<- )
问题回答

暂无回答




相关问题
Sorted quantile mean via Rpy

The real goal here is to find the quantile means (or sums, or median, etc.) in Python. Since I m not a power user of Python but have used R for a while, my chosen route is via Rpy. However, I ran into ...

How to create an empty R vector to add new items

I want to use R in Python, as provided by the module Rpy2. I notice that R has very convenient [] operations by which you can extract the specific columns or lines. How could I achieve such a function ...

Python Rpy R data processing optimization

I am writing a data processing program in Python and R, bridged with Rpy2. Input data being binary, I use Python to read data out and pass them to R, then collect results to output. Data are ...

How to suppress error messages in rpy2

The following code does not work. It seems that the R warning message raises a python error. # enable use of python objects in rpy2 import rpy2.robjects.numpy2ri import numpy as np from rpy2....

Converting python objects for rpy2

The following code is supposed to create a heatmap in rpy2 import numpy as np from rpy2.robjects import r data = np.random.random((10,10)) r.heatmap(data) However, it results in the following ...

热门标签