On 12/05/10 22:23, John Owens wrote:
> John Owens<john_owens<at> yahoo.com> writes:
>
>> and I also don't know how to replace that (python) vector back into the
>> DataFrame (I can use cbind to make a new column, but I'd rather replace the
>> old
>> column with the new one).
>
> I totally don't know how to do this, by the way, and would love a
> nudge toward the right answer.
The R-style way to do it is currently a bit uneasy for the non
initiated, unfortunately. Note that a copy of the data.frame is made.
>>> from rpy2.robjects.packages import importr
>>> base = importr('base')
>>> print(df)
a b
1 1 4
2 2 5
3 3 6
>>> print(base.__dict__['$<-'](df, 'a', 123))
a b
1 123 4
2 123 5
3 123 6
The Python way is more straightforward, and the replacement is done
in-place.
>>> df[0] = ro.IntVector((123, ))
>>> print(df)
a b
1 123 4
2 <NA> 5
3 <NA> 6
Warning message:
In format.data.frame(x, digits = digits, na.encode = FALSE) :
corrupt data frame: columns will be truncated or padded with NAs
> Thanks.
>
> JDO
>
>
> ------------------------------------------------------------------------------
>
> _______________________________________________
> rpy-list mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/rpy-list
------------------------------------------------------------------------------
_______________________________________________
rpy-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rpy-list