Hi, I search a solution to record data in dynamic structures in R. I have an algorithm that will be executed each step and whose output is an array of doubles with unknown size. The solution I found is to use lists 1) I initialise my list l <- list() 2) and at a step numbered i I conacatain the new tab to the list vect <- algorithm() l <<--c( l , list(stepi=vect)) The problem is that the key "stepi" is here a constant, I'd like to use a variable like this x = paste("step",index,sep="") where index is the last index (i) l <<--c( l , list(x=vect)) --> this doesn't function, the key is named "x" not "stepi" If I write l <<--c( l , list(paste("step",index,sep="") =vect)), I receive an error Many thanks for your help -- Bilel -- Bilel [[alternative HTML version deleted]]
Hi, I found a solution: creating lists without using keys l<<-c(l,list(x)) Many thanks, 2009/8/4 Bilel MASMOUDI <bilel.masmoudi@gmail.com>> Hi, > > I search a solution to record data in dynamic structures in R. > I have an algorithm that will be executed each step and whose output is an > array of doubles with unknown size. > > The solution I found is to use lists > 1) I initialise my list > l <- list() > 2) and at a step numbered i I conacatain the new tab to the list > vect <- algorithm() > l <<--c( l , list(stepi=vect)) > > The problem is that the key "stepi" is here a constant, I'd like to use a > variable like this > x = paste("step",index,sep="") where index is the last index (i) > l <<--c( l , list(x=vect)) --> this doesn't function, the key is named "x" > not "stepi" > If I write l <<--c( l , list(paste("step",index,sep="") =vect)), I receive > an error > > Many thanks for your help > -- > Bilel > > -- > Bilel >-- Bilel [[alternative HTML version deleted]]
Patterns like these can help to do what you want: > lapply(setNames(1:3, paste("step", 1:3, sep="")), function(i) seq(i)) $step1 [1] 1 $step2 [1] 1 2 $step3 [1] 1 2 3 > setNames(list("the result"), paste("a", "name")) $`a name` [1] "the result" > -- Tony Plate Bilel MASMOUDI wrote:> Hi, > > I search a solution to record data in dynamic structures in R. > I have an algorithm that will be executed each step and whose output is an > array of doubles with unknown size. > > The solution I found is to use lists > 1) I initialise my list > l <- list() > 2) and at a step numbered i I conacatain the new tab to the list > vect <- algorithm() > l <<--c( l , list(stepi=vect)) > > The problem is that the key "stepi" is here a constant, I'd like to use a > variable like this > x = paste("step",index,sep="") where index is the last index (i) > l <<--c( l , list(x=vect)) --> this doesn't function, the key is named "x" > not "stepi" > If I write l <<--c( l , list(paste("step",index,sep="") =vect)), I receive > an error > > Many thanks for your help >