If I modify the code in the following way
m = ro.r['matrix'](range(4), nrow=2, ncol=2)

    idx = ro.IntVector([1,4])
    m2 = m.assign(idx, 33)

    print(m2)

I get the following matrix

     [,1] [,2]
[1,] 33   2
[2,] 1    33

I think the indices are like vector indices here, a single index, In
this case 1 and 4 is assigned to 33 which are [1,1] and [2,2]
respectively . Is there a way to access the matrix elements using pair
of indices?

On Sat, Feb 21, 2009 at 2:46 PM, Laurent Gautier <lgaut...@gmail.com> wrote:
> Sancar Adali wrote:
>>
>> I'm trying to access and update a particular element of a matrix to update
>> it
>>
>> for example in R,
>>
>> mat=matrix(0,nrow=2,ncol=2)
>> mat[0,0]= mat[0,0]+1
>
> In R, vector indexing starts at one; zero are silently ignored.
>
>> How do I do this in rpy2
>> do I have to use the low-level interface or can I use high-level interface
>>
>
> Using the high-level interface is possible.
>
> One way is:
>
> import rpy2.robjects as ro
>
> m = ro.r['matrix'](range(4), nrow=2, ncol=2)
>
> idx = ro.IntVector([1,1])
> m2 = m.assign(idx, 33)
>
> print(m2)
>
>
> Not as elegant as one could wish... the 2.1 series for rpy2 will hopefully
> have something nicer.
>
>
> L.
>
> PS: using the rpy2-numpy compatibility layer is an another way.
>



-- 
Sancar Adali
Johns Hopkins University
Graduate Student

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
rpy-list mailing list
rpy-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpy-list

Reply via email to