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.

------------------------------------------------------------------------------
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