473,378 Members | 1,319 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

rpy: parsing arrays from python to R


Hi,

I use rpy on linux to call R functions. Works fine up to the following
problem: How to parse arrays (no vectors, that means 2-dimensional) to
R without much effort?

The following code solves the problem (in two different ways).
However, it seems to me that there might be a way to do it more
efficiently.

rpy.r.assign("N", N)
rpy.r("A2 <- array(1:N^2, dim=c(N,N))")
rpy.r("A3 <- array(1:N^2, dim=c(N,N))")
for i in range(N): # two alternative ways to parse
arrays
rpy.r.assign("Wi", W[i])
rpy.r.assign("i", i+1)
rpy.r("""for( j in 1:N ){
A2[i,j] <- Wi[j]}""")
for k in range(N):
rpy.r.assign("k", k+1)
rpy.r("A3[i,k] <- Wi[k]")
print rpy.r("A3")
print rpy.r("A2")
As I see it, the problem is, that the 'assign' command works only
either for scalars or vectors (one-dimensional arrays but not more-
dimensional arrays). I tried it for 2-dimensional arrays and the
result is a list whose components are vectors. Again, this is easy to
convert to a two-dimensional array but the point here is that one has
to do it.

Maybe there are people using R with python who have some more
experience. I would be interested how they solved this problem.

Thanks!

Frank

Mar 27 '07 #1
0 1085

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: malv | last post by:
Did anybody manage to use pairs() or coplot() from python using the rpy module? In fact any information going a bit beyond Tim Churches' very useful examples on plot() usage in rpy would be highly...
1
by: Bo Peng | last post by:
Dear list, I am using rpy, a python module to control statistical package R from python. Running the following commands >>> from rpy import * >>> r.plot(0) will pass command 'plot' to R...
4
by: jason | last post by:
Hello: I installed the following: python-2.4.2.msi pywin32-207.win32-py2.4.exe R-2.2.1-win32.exe rpy-0.4.6-R-2.0.0-to-2.2.1-py24.win32.exe on a Windows XP (SP2) box.
1
by: libiger | last post by:
Hi, I am trying to perform multiple regression in python using rpy. I can get it to work for two arrays, however when I try to regress a matrix and an array (as in the following code) I get an...
0
by: Frank | last post by:
Hi, I use rpy to plot functions and have the following problem. When I execute the following code line by line (start python and then execute line by line) the resulting figure looks as it...
0
by: hnessenospam | last post by:
Howdy, I've been using rpy (1.0.1) and python (2.5.1) on my office computer with great success. When I went to put rpy on my laptop, however, I get an error trying to load rpy. "Unable to...
1
by: tkpmep | last post by:
I'm running Python 2.5.2 on Windows XP and need to interface with R, so I downloaded the R 2.6.2 statistical package and installed it, and did the same for RPy 1.02 (i made sure I got the version...
0
by: tkpmep | last post by:
I have just installed R and Rpy, and am experiencing an odd problem when driving R from Python - if I create a plot in R, the portion of the plot window that lies under the IDLE window in which I...
2
by: Mike P | last post by:
Hi experts, I've just seen there is an R module, what i can't see easily is if you can / how to import other modules for R into the Rpy module Can anyone advise on this? Cheers Mike
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.