Well, I don't know RPy nor Python enought, and maybe I misunderstand your
data structure, but did you tried the RPy corresponding to the R
function"as.data.frame(dl)"

Cheers


2008/12/13 Gary Strangman <str...@nmr.mgh.harvard.edu>

>
> Hi again,
>
> I have a list-of-lists that I want to convert to an R dataframe. (In R, it
> should end up as 306 rows by 12 columns.) The rpy2 instructions suggested
> in this forum were basically: (1) convert my list of lists to a list of
> array.array()s, (2) convert each array.array() to an RVector, (3) convert
> the list of RVectors to a TaggedList, and (4) convert the taggedlist to a
> RDataFrame. While a touch unwieldy, that all works fine ... in most cases.
>
> However, I have some datasets with string columns in my source data
> (categorical data). These cannot be converted by array.array(), as it
> doesn't accept strings. TaggedList appears to work fine (as shown below)
> if I skip step 1 above and create RVectors straight from lists. But when I
> convert a TaggedList created a list of RVectors created this way, I get
> one LONG dataframe (1 row by 12*306=3672 columns):
>
> [in what follows, dl is my data, a list of lists]
>
> >>> import rpy2.robjects as ro
> >>> import rpy2.rlike.container as rlc
> >>> thisd = map(ro.RVector,dl)
> >>> len(thisd)
> 12
> >>> map(len,thisd)
> [306, 306, 306, 306, 306, 306, 306, 306, 306, 306, 306, 306]
> >>> h
> ['subj', 'age', 'educ', 'pre', 'r_tot', 'post', 'r_tot2', 'mild',
> 'moderate', 'severe', 'cond', 'run']
> >>> len(h)
> 12
> >>> tl = rlc.TaggedList(thisd,h)
> >>> len(tl)
> 12
> >>> map(len,tl)
> [306, 306, 306, 306, 306, 306, 306, 306, 306, 306, 306, 306]
> >>> df = ro.RDataFrame(tl)
> >>> len(df)
> 3672
> >>>
>
> Is this a limitation? A bug? Or just a knowledge gap on my part? FWIW, I'm
> on linux, rpy2.0.0, python2.4.3, R2.8.0.
>
> I need to do this /lots/ of times (hundreds of thousands or more), so I
> would like this to be as efficient as possible. For the same reason, I
> don't want to save the data to disk and use r.read_table(). I could of
> course recode my strings to some numeric stand-ins and go the
> array.array() route, but I was hoping to carry the strings into R ......
>
> -best
> Gary
>
>
> ------------------------------------------------------------------------------
> SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
> The future of the web can't happen without you.  Join us at MIX09 to help
> pave the way to the Next Web now. Learn more and register at
>
> http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
> _______________________________________________
> rpy-list mailing list
> rpy-list@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/rpy-list
>



-- 
Marcos F. Silva
http://marcosfs2006.googlepages.com
------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you.  Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
rpy-list mailing list
rpy-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpy-list

Reply via email to