On 2017/4/30 23:17, Jinsong Zhao wrote:
Hi there,
I have a problem with assign(). Here is the demo code:
for (i in 1:10) {
# create a list with variable name as list_1, list_2, ..., etc.
assign(paste("list_", i, sep = ""), list())
# I hope to assign 5 to list_?[[1]], but I don't know how to code it.
# list_1[[1]] <- 5 # works, however
assign(paste("list_", i, "[[1]]", sep = "", 5) # does not work
# wrong code in previous message, the correct on should be:
assign(paste("list_", i, "[[1]]", sep = ""), 5) # does not work...
}
How to do? Is there any alternatives? Many thanks!
Best,
Jinsong
______________________________________________
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.