boot<-function(a,b,c){
media<-(a+b+c)/3
var_app<-var(a)
list(media=media,var_app=var_app)
}
boot(2,4,10)
simul<-function(S){
results<-rep(0,S)
for(i in 1:S){
results[i]<-boot(2,4,10)
}
var<-var(media)
mean_var<-mean(var_app)
var_var<-var(var_app)
list(var=var,mean_var=mean_var,var_var=var_var)
}
simul(5)
--
View this message in context: http://www.nabble.com/Simulation-function-tp25027993p25027993.html
Sent from the R help mailing list archive at Nabble.com.
______________________________________________
R-h...@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
> boot<-function(a,b,c){
+ media<-(a+b+c)/3
+ var_app<-var(a)
+ list(media=media,var_app=var_app)
+ }
> boot(2,4,10)
$media
[1] 5.333333
$var_app
[1] NA
>
> simul<-function(S){
+ results<-list()
+ for(i in 1:S){
+ results[[i]]<-boot(2,4,10)
+ }
+ var<-var(sapply(results, '[[', 'media'))
+ mean_var<-mean(sapply(results, '[[', 'var_app'))
+ var_var<-var(sapply(results, '[[', 'var_app'))
+ list(var=var,mean_var=mean_var,var_var=var_var)
+ }
> simul(5)
$var
[1] 0
$mean_var
[1] NA
$var_var
[1] NA
>
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390
What is the problem that you are trying to solve?