简体   繁体   中英

R - Creating Variables With For-Loop

[this question is edited]

I want to simplify my question - I hope that will lead to understanding enough to answer the more complex one myself.

How can I create the variables a:i in R with a for-loop?

for(i in a:i) { "create variable [i]"

}

Thank you very much for your help!

You can use assign

for(I in 1:6) { 
      assign(letters[I], 1)
}

Output

 list(a,b,c,d,e,f)
[[1]]
[1] 1

[[2]]
[1] 1

[[3]]
[1] 1

[[4]]
[1] 1

[[5]]
[1] 1

[[6]]
[1] 1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM