On Thu, Jan 21, 2010 at 8:35 PM, Massimo Di Stefano
<massimodisasha at yahoo.it> wrote:> Hi All,
>
> please aplogize me if my qustion is a bit OT here,
> but maybe is there someone that uses R from inside python
> using rpy or rpy2 interface.
> In [54]: x = rdiv( ( rdiff( x, rmin(x) ) ) , ( rdiff( rmax(x) , rmin(x) ) )
)
>
> In [55]: y = rdiv( ( rdiff( r_sorted, rmin(r_sorted) ) ) , ( rdiff(
rmax(r_sorted) , rmin(r_sorted) ) ) )
> Errore in .Primitive("-")("mymap at
data$elevation.dem", "mymap at data$elevation.dem") :
> ?argomento non numerico trasformato in operatore binario
> ------------------------------------------------------------
> Traceback (most recent call last):
> ?File "<ipython console>", line 1, in <module>
> ?File
"build/bdist.macosx-10.6-universal/egg/rpy2/robjects/__init__.py",
line 423, in __call__
> RRuntimeError: Errore in .Primitive("-")("mymap at
data$elevation.dem", "mymap at data$elevation.dem") :
> ?argomento non numerico trasformato in operatore binario
My non-existent Italian is telling me this is non-numeric argument in
binary operator. Something like:
> "hello" - "goodbye"
Error in "hello" - "goodbye" : non-numeric argument to
binary operator
- because you are subtracting the strings "mymap at
data$elevation.dem".
Tracking back, those strings come from:
r_sorted = rsort('mymap at data$elevation.dem', decreasing=True)
- which is sorting the string vector! Like this:
> sort('mymap at data$elevation.dem', decreasing=TRUE)
[1] "mymap at data$elevation.dem"
You want to sort the *value* of that object. You want to sort the
$elevation.dem column of the @data slot of the python R object mymap.
In a functional form which will translate to your style of rpy2 would
be this in R:
get("$")(slot(mymap,"data"),"elevation.dem")
You may need to get 'get' and 'slot' from r.robjects in the way
you
do other functions. This looks a bit weird to me, but I'm used to
rpy-1 - maybe rpy 2 is like this!
Hope that points you in the right direction.
Barry
--
blog: http://geospaced.blogspot.com/
web: http://www.maths.lancs.ac.uk/~rowlings
web: http://www.rowlingson.com/
twitter: http://twitter.com/geospacedman
pics: http://www.flickr.com/photos/spacedman