Hi list, I have run into a bit of an issue with the R-style element
extraction for an robjects.DataFrame. I'll try to explain my issue
with an example:
>>> d = {'a': robjects.IntVector((1,2,3)), 'b': robjects.IntVector((4,5,6))}
>>> dataf = robjects.DataFrame(d)
>>> print dataf
a b
1 1 4
2 2 5
3 3 6
Now, if I want to remove a column from this data.frame, I can do so
with something like this:
>>> dataf2 = dataf.rx(-2)
Which works fine, and produces a new data.frame as output
>>> print dataf2
a
1 1
2 2
3 3
However, if I now wanted to remove the last row for instance:
>>> dataf3 = dataf2.rx(-3, True)
>>> print dataf3
[1] 1 2
I no longer get a data.frame, but instead, I get an IntVector object.
This appears to be because I am working with a single column
data.frame, because if I do the above on the original data.frame
(dataf, with two columns), it works as expected:
>>> dataf4 = dataf.rx(-2, True)
>>> print dataf4
a b
1 1 4
2 2 5
A similar thing happens if I reduce the original data.frame down to
one column using the following syntax (note the added 'True' statement
for the rows argument):
>>> dataf5 = dataf.rx(True, -2)
>>> print dataf5
[1] 1 2 3
Can anyone think of any workarounds to fix this issue? What I'd really
like is a way to index by either columns or rows and still get back a
data.frame, even if it is just a one column data.frame.
Rpy2 version 2.1.4
R version 2.12.1 (2010-12-16)
Platform: x86_64-pc-linux-gnu (64-bit)
Cheers,
Carson
--
Carson J. Q. Farmer
ISSP Doctoral Fellow
National Centre for Geocomputation
National University of Ireland, Maynooth,
http://www.carsonfarmer.com/
|