Dear all, I want to create a list that contains 0,1,2,3, ..., 10000 as its elements. I used the following code, which apparently doesn't work very well. a <- 0 for(i in 1:10000) { a <- list(a, i) } The result is not what I wanted. So how to create the bind lists recursively so that the last element would be the newly added one while the previous elements all remain the same? Thanks! Daniel
On May 27, 2008, at 10:43 PM, Daniel Yang wrote:> Dear all, > > I want to create a list that contains 0,1,2,3, ..., 10000 as its > elements. I used the following code, which apparently doesn't work > very well. > > a <- 0 > for(i in 1:10000) { > a <- list(a, i) > } > > The result is not what I wanted. So how to create the bind lists > recursively so that the last element would be the newly added one > while the previous elements all remain the same?Hm, for the particular problem you are asking, I think that: as.list(0:10000) should do the trick. I m guessing it might not work for the real application you had in mind. If you insist on the for loop, then you can do the following: a <- list(0) for(i in 1:10000) { a <- c(a, i) } Though it's much smaller. In general, it is better to assign the correct size to the list to begin with, I believe.> Thanks! > DanielHaris Skiadas Department of Mathematics and Computer Science Hanover College
On 28/05/2008, at 2:43 PM, Daniel Yang wrote:> Dear all, > > I want to create a list that contains 0,1,2,3, ..., 10000 as its > elements. I used the following code, which apparently doesn't work > very well. > > a <- 0 > for(i in 1:10000) { > a <- list(a, i) > } > > The result is not what I wanted. So how to create the bind lists > recursively so that the last element would be the newly added one > while the previous elements all remain the same?a <- list() for(i in 1:10000) a[[i]] <- i (The word ``bind'' is inappropriate.) cheers, Rolf Turner ###################################################################### Attention:\ This e-mail message is privileged and confid...{{dropped:9}}