I have created a fair dice simulation however when I run it, only one element is stored out of 10. I need all 10 to have a random number between 1 and 6.
dice<-function(n){
a<-numeric(n)
for(m in 1:n){
b=sample(1:6, size = n, replace = TRUE)
}
if(1==b){
a[m]<-1
}
else if(2==b){
a[m]<-2
}
else if(3==b){
a[m]<-3
}
else if(4==b){
a[m]<-4
}
else if(5==b){
a[m]<-5
}
else if(6==b){
a[m]<-6
}
a
}
x<-dice(10)
I expect an output of: 5361324164, but the actual output is: 0000000003