Hello Ding,

It appears that either you don't have numpy properly installed, or  
that your copy of rpy was compiled without numpy support.

A simple workaround for this specific case would be to turn of  
conversion of r to python objects, so that the object 'x' remains an  
r matrix, rather than being converted into a python list object (if  
numpy was being properly used, the return object would be a numpy  
matrix).

Try this code:

from rpy import *
set_default_mode(NO_CONVERSION)
x = r.matrix(r.rnorm(100), 50, 2)

# returned as an R object
km_1 = r.kmeans(x, 2)
r.print_(km_1)

# returned and converted to a python object
set_default_mode(BASIC_CONVERSION)
km_2 = r.kmeans(x, 2)
print km_2

-Greg

On Feb 22, 2008, at 5:40PM , Ding Zhou wrote:

> Hi,
>
> I was trying get the rpy to work but was stuck. Would you help us with
> these simple rpy commands?
>
> I did the following:
>
> python
>
> from rpy import r
>
> x = r.matrix(r.rnorm(100), 50, 2)
>
> r.kmeans(x, 2)
>
> The error was:
>
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> rpy.RException: Error in as.double.default(x) : (list) object  
> cannot be
> coerced to 'double'
>
> I also tried:
>
> x = numpy.array(x) before r.kmeans but it didn't work.
>
> I was able to run the same thing in R by doing:
>
> x = matrix(rnorm(100), 50, 2)
> kmeans(x, 2)
>
> But the test with rpy failed miserably ... Any idea to help out?
>
> Thanks,
> -Ding.
>
> ---------------------------------------------------------------------- 
> ---
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> rpy-list mailing list
> rpy-list@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/rpy-list


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
rpy-list mailing list
rpy-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpy-list

Reply via email to