With rpy2 (although there is currently no formal class for factors):


import rpy2.robjects as ro

vec = ro.StrVector(("a", "b", "a", "b"))
vec = ro.r["factor"](vec)





On Thu, 2009-04-09 at 19:38 -0400, David Warde-Farley wrote:
> Hi all,
> 
> I'm somewhat new to Rpy, and trying to use the R random forests  
> package from Python, and depending on the type it receives for one  
> variable it switches behaviour. If I want it to do classification it  
> expects a "factor" for y, but I am at a loss for the easiest way to  
> call convert a python list to a factor that I can use in a call to  
> r.randomForest().
> 
> I suppose I could also use r('randomForest(...)') but that could would  
> require appropriately converting data matrices, etc. to text literals  
> that R can handle, which seems both a bit wasteful memory-wise (I'm  
> sure RPy already does this at some point) and non-obvious how to do  
> it.                   
> 
> ------------------------------------------------------------------------------
> This SF.net email is sponsored by:
> High Quality Requirements in a Collaborative Environment.
> Download a free trial of Rational Requirements Composer Now!
> http://p.sf.net/sfu/www-ibm-com
> _______________________________________________
> rpy-list mailing list
> rpy-list@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/rpy-list


------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
_______________________________________________
rpy-list mailing list
rpy-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpy-list

Reply via email to