>> 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.
>
> I have been undecided regarding the amount of guessing / wrappers rpy2 
> should provide. Going through a TaggedList is currently the way to go, 
> but depending on the feedback 2.1 could have this revised slightly.

For me (and I think others), the ideal case would be a way to make a 
dataframe straight from (1) a list of data rows, as they'd come from 
something like a flat text or Excel file, and (2) a numpy array (including 
object arrays). By "straight", I'm thinking of something like 
as.data.frame, which does not require the conversion path of 
list-of-lists-->list-of-RVectors-->TaggedList-->RDataFrame. Ideally, these 
would behave like R's read.table--figuring out the datatype of each 
column--but of course without requiring a file. This may be quite 
unrealistic to implement as a whole, but perhaps there are ways to 
eliminate some of the steps. (I have the added step of converting my 
list-of-rows--as the data comes from my files--to its transpose, a 
list-of-columns, before converting to RVectors.)

>> 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):
>
> You can use the class StrVector for vectors.
> (briefly mentioned at 
> http://rpy.sourceforge.net/rpy2/doc/html/robjects.html#creating-vectors)

Ah, I had missed that. Thanks.

-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

Reply via email to