Re: [R] How to quickly convert a data.frame into a structure of lists

2011-08-10 Thread William Dunlap
because they use split() to avoid the repeated > evaluations of > bigVector[ anotherBigVector == scalar ] > that your nested (not imbricated) loops do. If you really need to convert > the matrix to a list of lists that will probably be a quick transformation. > > Bill Dunl

Re: [R] How to quickly convert a data.frame into a structure of lists

2011-08-10 Thread William Dunlap
Spotfire, TIBCO Software wdunlap tibco.com > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf Of Duncan Murdoch > Sent: Wednesday, August 10, 2011 9:43 AM > To: Frederic F > Cc: r-help@r-project.org > Subject: Re

Re: [R] How to quickly convert a data.frame into a structure of lists

2011-08-10 Thread Eik Vettorazzi
Hi Frederic, shouldn't there be an result for the 3rd row as well, eg ls1$b$Y? Maybe this will do what you want? dtf<-within(dtf,index<-factor(A:B)) tapply(dtf$C,dtf$index,list) Hth. Am 10.08.2011 16:30, schrieb Frederic F: > Hello Duncan, > > Here is a small example to illustrate what I am

Re: [R] How to quickly convert a data.frame into a structure of lists

2011-08-10 Thread Duncan Murdoch
On 10/08/2011 10:30 AM, Frederic F wrote: Hello Duncan, Here is a small example to illustrate what I am trying to do. # Example data.frame df=data.frame(A=c("a","a","b","b"), B=c("X","X","Y","Z"), C=c(1,2,3,4)) # A B C # 1 a X 1 # 2 a X 2 # 3 b Y 3 # 4 b Z 4 ### First way of getting the list

Re: [R] How to quickly convert a data.frame into a structure of lists

2011-08-10 Thread Frederic F
Hello Denis, > To borrow shamelessly from one of the prominent helpers on this list: > "What is the problem you're trying to solve?"    (attribution: Jim Holtman) I'm trying to connect two sets of legacy R tools: the output of the first one can be transformed in a data.frame without loss of inf

Re: [R] How to quickly convert a data.frame into a structure of lists

2011-08-10 Thread Frederic F
Hello Duncan, Here is a small example to illustrate what I am trying to do. # Example data.frame df=data.frame(A=c("a","a","b","b"), B=c("X","X","Y","Z"), C=c(1,2,3,4)) # A B C # 1 a X 1 # 2 a X 2 # 3 b Y 3 # 4 b Z 4 ### First way of getting the list structure (ls1) using imbricated lapply

Re: [R] How to quickly convert a data.frame into a structure of lists

2011-08-10 Thread Dennis Murphy
To borrow shamelessly from one of the prominent helpers on this list: "What is the problem you're trying to solve?"(attribution: Jim Holtman) I have the sense you want to do something over many subsets of your data frame. If so, breaking things up into lists of lists of lists is not necessari

Re: [R] How to quickly convert a data.frame into a structure of lists

2011-08-10 Thread Duncan Murdoch
I would use the tapply function (which is designed for the case in which data exists for most pairs of the levels of A and B) or the reshape::sparseby function, or something else in the reshape package. These won't give you exactly the structure you were asking for, but they will separate the d

Re: [R] How to quickly convert a data.frame into a structure of lists

2011-08-09 Thread Duncan Mackay
Hi Something to get you started ? as.list a data.frame can be regarded as a 2 dimensional array of list vectors df = data.frame(a=1:2,b=2:1,c=4:5,d=9:10) as.list(df[,1:3]) $a [1] 1 2 $b [1] 2 1 $c [1] 4 5 see also http://cran.ms.unimelb.edu.au/doc/contrib/Burns-unwilling_S.pdf Regards Dunca

[R] How to quickly convert a data.frame into a structure of lists

2011-08-09 Thread Frederic F
Hello, This is my first project in R, so I'm trying to work 'the R way', but it still feels awkward sometimes. The problem that I'm facing right now is that I need to convert a data.frame into a structure of lists. The data.frame has columns in the order of tens (I need to focus on only three of