max=sample(1:10,6,replace=F)
temp <- list()
for (n in 1:5){
neighborList=list()
for ( i in 1:max[n]){
num=sample(15:49,20,replace=F)
neighborList[i] = 0
for (j in 1:num[i])
{
neighborList[[i]][j] = i*j
}
}
temp[[n]] <- neighborList
}
Doesn't temp[[1]]
or temp[1]
already give you what you want, i.e. the first neighborList that was generated when n=1?