Error in do.call

Hi I try to create a loop for uniform Distribution for my homework
and this is my code, when I run i get this error, "Error in do.call(c, mean_uni) :
'what' must be a function or character string
In addition: There were 50 or more warnings (use warnings() to see the first 50)"
can someone help me fix this
Uniform_Distribution = function(samples, size, min, max){
uni_size = samples

set.seed(22)
uni = list()
for (i in 1:uni_size) {
uniform_samples = runif(n = size, min, max)
uni[[i]] = uniform_samples
}

mean_uni = list()

for (j in 1:length(uni)) {
mean1 = mean(uni[j])
mean_uni[[j]] = mean1
}

means_unidistri = do.call(c,mean_uni)
means_unidistri
}

means_unidistri = Uniform_Distribution(samples = 100, size = 30, min = 0, max = 1)

means_unidistri

Can you change your title so that it is more informative? Can you choose a better category too? Nothing to do with rstudio::conf.

The problem is because of this line:

If you want to access an element of a list, use [[ instead of [. Actually, you could have used sapply to get as a vector instead of list directly in that way.


If I understand what you are trying to do, this is probably a better way:

x <- replicate(100, runif(30, 0, 1))
y <- colMeans(x)

Hope this helps.


Edit:

Yes, none of the for loops are required any more. replicate will handle the first one, and colMeans the 2nd one.

I have to create 100 samples of some distribution, size 30 from Uniform U(0,1) and calculate the sample means, i guess i don't need the loop?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.

Sorry my mistake, second time using the community.