[R] building a list in loop

Uwe Ligges ligges at statistik.uni-dortmund.de
Sat Mar 27 16:46:54 CET 2004


Fred J. wrote:

> Hello
> 
> getdata <- function(p){
> fname <- NULL; dl <- list()#build the sturcture
>   builddl <- function(q,s){
>    fname <<- c(fname,s) #where "s" is a string
>    dl <<- list( dl, dt2)

"Fred J." alias "phddas", you are really not going to use <<- here, 
please read the manuals.


>  }
>  list(names = fname, data = dl)
> }
> data <- getdata("c:\somepath")

This won't work, please read the R for Windows FAQs.


> 
>>data
> 
> $names
> [1] "fname"
> 
> $data
> $data[[1]]  <--- since there is no [[1]] how can I
> stop 

It's just a matter of printing the list, in one list elements are named, 
in the other elements are unnamed.


> list()      <--- this from happening? 

What are you going to stop???

I guess some kind souls on this list would be happy to help, but you 
need to specify your problem precisely enough! In this case, I don't 
understand your problem, and I even do not understand your question.

Let me cite the last line of all R-help messages:
"PLEASE do read the posting guide! 
http://www.R-project.org/posting-guide.html".

Uwe Ligges


> $data[[2]]
> ... lists all rows and cols here
> 
> thanks
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html




More information about the R-help mailing list