Java Mailing List Archive

http://www.r-help.com/

Home » R Help for Statistical Computing »

[R] Function try and Results of a program

Evgenia

2010-09-04

Replies: Find Java Web Hosting

Author LoginPost Reply

Hello, users.

Dear users,

*******I have a function f to simulate data from a model (example below used
only to show my problems)

f<-function(n,mean1){
a<-matrix(rnorm(n, mean1 , sd = 1),ncol=5)
b<-matrix(runif(n),ncol=5)
data<-rbind(a,b)
out<-data
out}

*********I want to simulate 1000 datasets (here only 5) so I use
S<-list()

for (i in 1:5){
S[[i]]<-f(n=10,mean1=0)}

******I have a very complicated function for estimation of a model which I
want to apply to Each one of the above simulated datasets

fun<-function(data){data<-as.matrix(data)
sink(' Example.txt',append=TRUE)
      cat("\n***********************\nEstimation
\n********************\nDataset Sim : ",
       i )
d<-data%*%t(data)
s<-solve(d)
print(s)
out<-list (s,d)
out
}
results<-list()
for(i in 1:5){
  tmp <- try(fun(data=S[[i]]))
  results[[i]] <- ifelse(is(tmp,"try-error"),NA,tmp)
}

####My problem is that results have only the 1st element of the result lists
of fun (i.e. only ####although tmp gives me both s and d.

Thanks

Evgenia


--
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help@(protected)
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.
©2008 r-help.com - Jax Systems, LLC, U.S.A.