Hello,
I'm beggining on R and i'm trying to create a function which gives me a vector of randow numbers.
For that, i do like this :
The problem is that i want to make a print of the mean and the standard deviation of thoses random numbers but i can't do it.
Thank you for your help.
If I've understood your problem this chunk of code will satisfy:
Random <- function (x)
{
Vector<-c(rnorm(x))
paste("The mean is",mean(Vector),"and the standard deviation is:",sd(Vector),".")
}
Random(10)
Thanks for your answer.
But in fact, the work i have to do must follow 2 steps :
-
- To generate a vector of random numbers
-
- To use "print" to give the mean and the standard deviation of those random numbers of step 1.
You mean something like this?
Random <- function (x)
{
Vector<-c(rnorm(x))
writeLines("The generated vector is:")
print(Vector)
writeLines(paste0("The mean is ",mean(Vector),", and the standard deviation is ",sd(Vector),"."))
}
Random(10)
That is exactly the result i wanted, thank you very much for your help