I am new to the language R. I have a function and am trying to make a list that uses that function to create 1000 entries to the list, to then make a histogram.
This is my code that I have tried:
for (i in 1:1000)
zscores[i] <- Reduce("+", runif(12)) - 6
hist(zscores)
I am getting an number for i[1] and i[1000], but for all the other entries I get NA when I should be getting a number. What am I doing wrong?
>Solution :
I didn’t get any NAs running your code this way
zscores <- c()
for (i in 1:1000) {
zscores[i] <- Reduce("+", runif(12)) - 6
}
hist(zscores)
Or running the way Gregor Thomas mention
zscores <- c()
for (i in 1:1000) {
zscores[i] <- sum(runif(12)) - 6
}
hist(zscores)
