Re: [R] dynamic lists (data frames?)

From: Vincent Goulet <vincent.goulet_at_act.ulaval.ca>
Date: Wed 28 Sep 2005 - 04:44:29 EST

Le 27 Septembre 2005 10:39, tom wright a écrit :
> Can someone please show me what I need to get something like this to
> work
>
> for(a in c(1:5)){
> data$a<-c(a:10)
> }
>
> so that i end up with a structure
> data$1<-[1,2,3,4,5,6,7,8,9,10]
> data$2<-[2,3,4,5,67,8,9,10]
> data$3<-[3,4,5,67,8,9,10]
> data$4<-[4,5,67,8,9,10]
> data$5<-[5,67,8,9,10]
>
> thanks loads
> Tom

That's an exercise I give to my students! This will create the sequences:

> data <- lapply(1:5, seq, 10)

You can then assign the names with

> names(data) <- as.character(1:5)

but 'data$1' will not work. You will need either 'data$"1"' or 'data[["1"]]'. I'd use different names...

HTH.

-- 
  Vincent Goulet, Associate Professor
  École d'actuariat
  Université Laval, Québec 
  Vincent.Goulet_at_act.ulaval.ca   http://vgoulet.act.ulaval.ca

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Wed Sep 28 04:54:28 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 17:49:52 EST