Hi,

As an exercise, I am trying to create a list of 10 random number vectors in a 
loop. I can create the vectors but am unsure how to assemble them in the list 
as part of the loop. Any advice?


# Number of vectors to create
n <- c(1:10)

# Create empty list to store vectors
list_of_vecs <- list()

# Create n vectors of random numbers - length 10. This works ok.
for (i in seq_along(n)){
  assign(paste('vec_', i, sep = ''), rnorm(10,0,1))
}

# But how do I append them in a list. This doesn’t work:
for (i in seq_along(n)){
  list_of_vecs <- list(list_of_vecs,(assign(paste('vec_', i, sep = ''), 
rnorm(10,0,1))))
}


Thank you,

Paul



        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to