Some background: First, I wanted to generate multiple sets of samples (each of sample size n) from a uniform (0,1) distribution in [R]. I know that the command for generating from a uniform distribution is runif(n=x) for some sample size x, e.g. if I wanted sample size 20 the command would be
runif(n=20)
Next, I used the command
replicate( 100, runif(n=20))
This generated a double matrix of values which I could then convert into a dataset with 100 columns and 20 rows.
Is it possible for me to generate a dataset consisting of the sample means of all the column vectors (the sample means of the 100 sets taken from the uniform distribution)?
Thank you for your help.
To create a vector of data frame values by rows we can use c function after transposing the data frame with t. For example, if we have a data frame df that contains many columns then the df values can be transformed into a vector by using c(t(df)), this will print the values of the data frame row by row.
How to add columns to a data frame in R?, To add one or more columns to a data frame in R, use the mutate() function from the dplyr package. With the following data frame, the following examples demonstrate how to use this syntax in practice.
You can use colMeans
.
data <- replicate(100, runif(n=20))
means <- colMeans(data)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With