-2

so I just started programming in R and am still pretty unfamiliar with the software.

Recently, I was tasked with finding the means (separately) of a replicated group of data, where my main function is a simple continuous uniform distribution.

After generating 500 replications of the distribution using runif(5, min = 15, max = 30), this table was created.

500 data replications

What I'm currently looking for to find the sample mean for each version (V1, V2, etc.) separately, and have it paste out like this, but with 500 different means.

enter image description here

Is there a method to generate the data table first (as I already did), before finding the sample mean later? I tried using meanreplicate5 <- replicate(500, mean(replicate5)), seeing "replicate5" was already defined with the data table, but it just gave me 500 values of the same number, 22.5.

Thank you for reading!

aNode
  • 29
  • 4
  • 1
    `apply(replicate5, 1, mean)`? – Allan Cameron Jun 17 '20 at 14:59
  • 1
    Does this answer your question? [Column mean of data.frame (list) in R](https://stackoverflow.com/questions/25467904/column-mean-of-data-frame-list-in-r). See for example the second answer using [`colMeans`](https://stackoverflow.com/a/25469584/10782538) – Oliver Jun 17 '20 at 15:04
  • Using `replicate(500, mean(runif(5, min = 15, max = 30)))` would've also given expected output (much slower than generating the mtrix and using `colMeans`) – Oliver Jun 17 '20 at 15:06
  • @AllanCameron brilliant, apply(replicate5, 2, mean) got me the result I wanted. Thanks for showing me the apply function! – aNode Jun 17 '20 at 15:08
  • @Oliver, Ahh, I see, I'll give your function a try! My lecturer did mention something like that, but I was just wondering if it was possible to generate and calculate separately. – aNode Jun 17 '20 at 15:10

1 Answers1

0

Answer was given by @Allan Cameron using the apply function: apply(replicate5, 2, mean).

aNode
  • 29
  • 4