On 2011-10-05 02:48, William T. Martin wrote: > I have a string s="70 75 none 80" that I would like to convert to an > robjects.FloatVector f, which in R would be f<-(70, 75, NA, 80) > > Under py2-2.0, this works for me: > >>>> import rpy2.robjects as robjects >>>> readings="70 80 none 90" >>>> f=robjects.FloatVector(readings.split(" ")) >>>> print(f) > [1] 70 80 NA 90 > > Under py2 2.3.0dev, I get the following: > >>>> import rpy2.robjects as robjects >>>> readings="70 80 none 90" >>>> f=robjects.FloatVector(readings.split(" ")) > Traceback (most recent call last): > File "<stdin>", line 1, in<module> > File > "/usr/local/lib/python2.7/dist-packages/rpy2/robjects/vectors.py", line > 402, in __init__ > obj = FloatSexpVector(obj) > ValueError: Error while trying to convert element 2 to a double. > > What is the current way to get f<-(70, 75, NA, 80)?
You seem to be relying on R's "magic". With Python: >>> float("70") 70.0 >>> float("none") Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: could not convert string to float: none >>> float("None") Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: could not convert string to float: None If you want to do things on the Python side, you'll have to indicate how to represent strings that are not numbers (Python's "better explicit than implicit" ). FloatVector([ro.NA_Real if x == "none" else float(x) for x in readings.split(" ")]) > Thank you > > Bill > > > > > > > ------------------------------------------------------------------------------ > All the data continuously generated in your IT infrastructure contains a > definitive record of customers, application performance, security > threats, fraudulent activity and more. Splunk takes this data and makes > sense of it. Business sense. IT sense. Common sense. > http://p.sf.net/sfu/splunk-d2dcopy1 > _______________________________________________ > rpy-list mailing list > rpy-list@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/rpy-list ------------------------------------------------------------------------------ All the data continuously generated in your IT infrastructure contains a definitive record of customers, application performance, security threats, fraudulent activity and more. Splunk takes this data and makes sense of it. Business sense. IT sense. Common sense. http://p.sf.net/sfu/splunk-d2dcopy1 _______________________________________________ rpy-list mailing list rpy-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rpy-list