On Mon, Sep 12, 2011 at 12:26 PM, Laurent Gautier <lgaut...@gmail.com> wrote: > Probably not. > > R is doing a lot of things behind the hood. Sometimes it is good, sometimes > it is bad. > The code snippet given to you has a quadratic time-complexity ( O(nm) ). It > can be make linearithmic ( O(n log(m) ) ) simply: > > from rpy2.robjects.vector import BoolVector > ref = set(differential) > select_b = BoolVector(tuple(x in ref for x in source.rx2('gene'))) > mysubset = source.rx(select_b, True)
If I reckon well BoolVector(...genexpr...) is not possible here due to R API limitation - we need length of iterable, isn't it? It seems like copying R on Python level is not always nice and can be quite inefficient. Above probably could be rewritten in more Pythonic way (it would be more efficient I believe, as well) mysubset = source.rx((x in ref for x in source.rx2('gene')), True) or mysubset = DataFrame(row for row in source if row['gene'] in ref) but of course is not supported by rpy2. Is there a chance to make rpy2 bit more Python integrated? :) Best regards, w ------------------------------------------------------------------------------ Doing More with Less: The Next Generation Virtual Desktop What are the key obstacles that have prevented many mid-market businesses from deploying virtual desktops? How do next-generation virtual desktops provide companies an easier-to-deploy, easier-to-manage and more affordable virtual desktop model.http://www.accelacomm.com/jaw/sfnl/114/51426474/ _______________________________________________ rpy-list mailing list rpy-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rpy-list