473,785 Members | 2,275 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("W i", 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 1098

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

Similar topics

0
277
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 welcome. Thx. malv
1
1971
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 and run it. I notice that the R-plot will not refresh (a window is created but the figure is not drawn) until the
4
2516
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
2546
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 error message (below.) Can someone please help? Thanks, Ondrej
0
1128
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 should. However, when I put these lines in a script and execute the script the figure appears for half a second but then crashes. Using pylab.show() at the end of the script prevents the crash but now the window is no longer refreshed (e.g., changing...
0
889
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 determine R version from the registry. Trying another method." followed by a few lines of the usual error message style (ending with "NameError: global name 'RuntimeExecError' is not defined." I have reinstalled R (now 2.6.1), rpy, and python...
1
1917
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 for Python 2.5 and R 2.62.). When I go to the Python command line and type I get the following error message: Traceback (most recent call last): File "<pyshell#7>", line 1, in <module> from rpy import *
0
761
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 type my Python code remains blank. So if I type I get a plot of y vs. x, but only the top right portion of the plot shows any points, axes etc. The bottom left corner (the portion that lay under the IDLE window) is blank. Is this a known...
2
1182
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
0
9647
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9489
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10162
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10101
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8988
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5396
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5528
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4063
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.