I want to generate a column of normal random variables with mean defined in the dep variable. However, I got the non-random results.
I know there are other ways to do it like apply functions (sapply(1:5, rnorm, n=1)
), but I am just curious to know how to do it using dplyr and why I got the mistakes.
library(dplyr)
data_frame(dep = 1:5) %>%
mutate(normal_mean = rnorm(1, mean=dep))
Source: local data frame [5 x 2]
dep normal_mean
1 1 1.574045
2 2 1.574045
3 3 1.574045
4 4 1.574045
5 5 1.574045