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
information, the input of the second one takes the form of a structure
of list.

>  it's entirely possible
> that there may be a nice 'R way' to do it. Read the posting guide and
> if at all possible, provide a small, reproducible example that
> demonstrates what you want to accomplish.

Here is the first way attacked the problems illustrated on a tiny
dataset (this way does not work quickly enough on a real dataset
unfortunately):

df=data.frame(A=c("a","a","b","b"), B=c("X","X","Y","Z"), C=c(1,2,3,4))

# Get the structure and populate it:
ls1<-lapply(levels(df$A), function(levelA) {
      lapply(levels(df$B), function(levelB) {df$C[df$A==levelA & df$B==levelB]})
})
# Get the names:
names(list_structure)<-levels(df$A)
for (i in 1:length(list_structure)) {names(list_structure[[i]])<-levels(df$B)}

# Results:
ls1$a$X
# [1] 1 2
ls1$b$Z
# [1] 4

Thanks for your help,

Frederic


--
View this message in context: http://r.789695.n4.nabble.com/How-to-quickly-convert-a-data-frame-into-a-structure-of-lists-tp3731746p3733114.html
Sent from the R help mailing list archive at Nabble.com.
	[[alternative HTML version deleted]]

