I have a question with regard to naming the columns that come out of the purrr (Tidyverse) map_dfc function.
I have a function that outputs a single number, let's say this function is rnorm(). I would like to replicate this function n = 10 times with different values for the mean and save the output to a dataframe, with the column names being the names of the mean.
library(purrr)
f_replicates <- function(n){
replicate(n=10, rnorm(n=1, mean = n))
}
map_dfc(c(4, 10, 20), f_replicates)
This creates a tibble, where the column names are set to
New names:
- NA -> ...1
- NA -> ...2
- NA -> ...3
Question
How do you create a dataframe with the means as column names?