Hey Kent,

Well i've gotten exactly no response on the Rpy-list on both my questions
:-(.

However i switched to Ubuntu 6.10 today (from WinXP) and to my suprise it
does work under linux! :-)

RHOME= /usr/lib/R
RVERSION= 2.3.1
RVER= 2031
RUSER= /home/geofram
Loading Rpy version 2031 .. Done.
Creating the R object 'r' ..  Done

In [2]: r.diag(2)
Out[2]:
array([[ 1.,  0.],
      [ 0.,  1.]])

In [3]: r.kmeans(r.diag(2),1,2,5,"Forgy")
Out[3]:
{'centers': array([       [ 0.5,  0.5]]),
'cluster': [1, 1],
'size': 2,
'withinss': 1.0}

Older version somewhat but apparently this works, so it might just be a bug
under windows or in the newer version from Rpy... For now at least I can
work with it.

Thanx a bunch for all your help Kent.

Regards - Geofram

On 12/25/06, Kent Johnson <[EMAIL PROTECTED]> wrote:

Geoframer wrote:

> As i stated i think the conversion from Python to R is going wrong, but
> i have no clue on how to properly address that.

I agree. If you have Numeric installed (which I do) then r.diag() should
return a Numeric array, not a list of lists. This looks like the same
problem discussed in this thread:
http://sourceforge.net/mailarchive/message.php?msg_id=15307721
which does not seem to have been resolved.

I don't want to get involved in the Rpy mailing list but I would suggest
posting a very simple question asking why the result of r.diag() is not
a Numeric array. Perhaps this will lead to a solution.

> The code snippet i was talking about is on page 15 and 16 of the rpy
> reference guide http://rpy.sourceforge.net/rpy/doc/rpy.pdf ; the
> examples just don't work and i am lacking enough python experience to
> see why :-S.
>
> What i'm trying to do now is :
>
> ----
> from rpy import *
>
> class Test:
>     def as_r(self):
>         return
[[1,2,3,4,5],[2,3,4,5,1],[3,4,5,1,2],[4,5,1,2,3],[5,1,2,3,4]]
>
> if __name__ == "__main__":
>     a=with_mode(NO_CONVERSION, Test)()
>     r.kmeans(a, 2, 5, 10, "Forgy")

I don't see how this will help. My understanding is that as_r() should
return an Robj, not a Python object. I think this code is the same as
passing a list of lists directly to kmeans.

Kent


_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to