Hello I am trying to create a list by appending to list element using for loops. Here is my code
list_additive <- list(alpha_a = c(),
beta_a = c(),
gamma_a = c())
for(a in 0.1:1){
for(b in 0.1:1){
for(g in 0.1:1){
append(list_additive$alpha_a, a)
append(list_additive$beta_a,b)
append(list_additive$gamma_a,g)
g = g + 0.1
}
b = b +0.1
}
a = a + 0.1
}
list_additive
my final result I want to create a data frame like the following
aplha beta gamma
0.1 0.1 0.1
0.1 0.1 0.2
0.1 0.1 0.3
.
.
0.1 0.2 0.1
0.1 0.2 0.2
Hi @pikud1990,
Welcome to the RStudio Community Forum.
Nested for() loops are usually a suboptimal approach in R and are often a paradigm hangover from other languages. However, assuming you intended to produce 10^3 combinations, this example will work (see below), but also illustrates a simpler and safer way to achieve the same result: