In R, how to generate a dataset consisting of the means of all column of a dataframe?
dataset, distribution, r, replicate, simulation
Solution
You can use `colMeans`.
data <- replicate(100, runif(n=20))
means <- colMeans(data)
Problem
I can generate 20 observations of a uniform distribution with the runif function : ` runif(n=20)` and 100 replicates of the same distribution as following. ``` df <- replicate( 100, runif(n=20)) ``` This creates `df` a matrix of dimensions `[20,100]` which I can convert into a data frame with 100 columns and 20 rows. How can I generate a new data frame consisting of the means of each column of `df` ? Thank you for your help.