[R] Problems when Apply a script to a list
Evgenia
evgts at aueb.gr
Thu Aug 26 11:20:46 CEST 2010
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<-s
out
}
results<-list()
for (i in 1:5){results[[i]]<-fun(data=S[[i]])}
My questions are:
1) for some datasets system is computational singular and this causes
execution of the for to stop.By this way I have only results until this
problem happens.How can I pass over the execution for this step and have
results for All other datasets for which function fun is applicable?
2) After some runs to my program, I receive this error message someError in
sink("output.txt") : sink stack is full . How can I solve this problem, as I
want to have results of my program for 1000 datasets.
3) Using for is the correct way to run my proram for a list
Thanks alot
Evgenia
--
View this message in context: http://r.789695.n4.nabble.com/Problems-when-Apply-a-script-to-a-list-tp2339403p2339403.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list