Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

generate variable names (something like get())

How can i substitute this code with a loop?

m1 <- ggplot(foo)
m2 <- ggplot(foo)
...
m9 <- ggplot(foo)

I guess i need something like get() to replace magic(), But get did not work here.

for (i in 1:9){
  magic(i) <- ggplot(foo)
}
like image 236
Jonas Stein Avatar asked Apr 09 '26 13:04

Jonas Stein


1 Answers

Use a list:

out <- list()

for (i in 1:9){
  out[[i]] <- ggplot(foo)
}
like image 197
hadley Avatar answered Apr 12 '26 01:04

hadley



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!