I want a function to calculate the mean and variance of a vector at the same time (with a vector output) such that if I only want the value of the mean or only that of the variance I will only subset it with a $
sign.
x <- function(n, a, b, mean, sd){
meann = mean(truncnorm::rtruncnorm(n, a, b, mean, sd))
std = sd(truncnorm::rtruncnorm(n, a, b, mean, sd))
return(c(meann, std))
}
x(n=100, a = -1, b = 1, mean = 0, sd = 1)
If I want mean I will write x$meann
and if I need standard deviation I will write x$std