Since you asked for a one-liner:
rnorm2 <- function(n,mean,sd) { mean+sd*scale(rnorm(n)) }
r <- rnorm2(100,4,1)
mean(r) ## 4
sd(r) ## 1
More Related Contents:
- object I am trying to take the mean of is not found
- Stratified random sampling from data frame
- Sample random rows in dataframe
- Calculate group mean, sum, or other summary stats. and assign column to original data
- Reasons for using the set.seed function
- calculate the mean for each column of a matrix in R
- how to calculate mean/median per group in a dataframe in r [duplicate]
- Generate N random integers that sum to M in R
- efficiently generate a random sample of times and dates between two dates
- Sample n random rows per group in a dataframe
- Reading multiple files and calculating mean based on user input
- How to randomize (or permute) a dataframe rowwise and columnwise?
- Mean of a column in a data frame, given the column’s name
- calculating mean for every n values from a vector
- Standard Deviation in R Seems to be Returning the Wrong Answer – Am I Doing Something Wrong?
- from data table, randomly select one row per group
- Get the means of sub groups of means in R
- Add error bars to show standard deviation on a plot in R
- Generating Random Strings
- Generate correlated random numbers from binomial distributions
- How do I best simulate an arbitrary univariate random variate using its probability function?
- Extract rows based on only one column using R [closed]
- cbind a dataframe with an empty dataframe – cbind.fill?
- Installation of RODBC/ROracle packages on OS X Mavericks
- R help page as object
- Convert a character vector of mixed numbers, fractions, and integers to numeric
- Options for caching / memoization / hashing in R
- R – Markdown avoiding package loading messages
- Add row in each group using dplyr and add_row()
- list of masked functions in R