[R] Export Results to a txt file applying a function to a list
Dear users, ***I have a function f to simulate data from a model (example below used only to show my problem) 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 } ##First using for I take my results (for some element of a list I can't have results due to invertibility or convergence problem helpful suggestion of Joris Meys ) results<-list() ffor(i in 1:5){ tmp <- try(fun(data=S[[i]])) results[[i]] <- ifelse(is(tmp,"try-error"),NA,tmp) } #and so I can see using "cat" the results for each dataset. #I want to use lapply at the last step istead of for to make faster my program results <- lapply(S,function(x){ tmp <- try(fun(data=x)) ifelse(is(tmp,"try-error"),NA,tmp) } ) # My question is how can I export results to a file knowing exactly for which of the element of the list these are (for some element of a list I can't have results due to invertibility or convergence problem) Thanks alot Evgenia -- View this message in context: http://r.789695.n4.nabble.com/Export-Results-to-a-txt-file-applying-a-function-to-a-list-tp2401218p2401218.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] Export Results
Do you have an open word file ? Contact Details:--- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) -- On Mon, Jun 28, 2010 at 1:38 PM, Pedro Mota Veiga wrote: > > Thanks for your sugestions. > > But when I do "wdGet(T)" I have de next message. > > wdGet(T) > Error in if (!(tmp[["ActiveDocument"]][["Name"]] == filename)) > tmp$Open(paste("path", : > argument is of length zero > > What is happen? > > Thaks for all > -- > View this message in context: > http://r.789695.n4.nabble.com/Export-Results-tp2268622p2270745.html > Sent from the R help mailing list archive at Nabble.com. > > __ > R-help@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. > [[alternative HTML version deleted]] __ R-help@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.
Re: [R] Export Results
Thanks for your sugestions. But when I do "wdGet(T)" I have de next message. > wdGet(T) Error in if (!(tmp[["ActiveDocument"]][["Name"]] == filename)) tmp$Open(paste("path", : argument is of length zero What is happen? Thaks for all -- View this message in context: http://r.789695.n4.nabble.com/Export-Results-tp2268622p2270745.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] Export Results
On Sat, Jun 26, 2010 at 7:42 AM, Tal Galili wrote: > And there are also the "brew", and "Sweave" packages (as Henrique > mentioned). > Also, odfWeave and Sweave via LyX. I believe that this is FAQed. Liviu __ R-help@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.
Re: [R] Export Results
See ?pdf ?png ?sink There is also R2wd (about which I wrote here: http://www.r-statistics.com/2010/05/exporting-r-output-to-ms-word-with-r2wd-an-example-session/ ) And there are also the "brew", and "Sweave" packages (as Henrique mentioned). Best, Tal Contact Details:--- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) -- On Fri, Jun 25, 2010 at 6:58 PM, Pedro Mota Veiga wrote: > > Hi R users, > How can I automatically export results and graphs to a file? > Thanks in advance > > Pedro Mota Veiga > > -- > View this message in context: > http://r.789695.n4.nabble.com/Export-Results-tp2268622p2268622.html > Sent from the R help mailing list archive at Nabble.com. > > __ > R-help@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. > [[alternative HTML version deleted]] __ R-help@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.
Re: [R] Export Results
See ?Sweave On Fri, Jun 25, 2010 at 12:58 PM, Pedro Mota Veiga wrote: > > Hi R users, > How can I automatically export results and graphs to a file? > Thanks in advance > > Pedro Mota Veiga > > -- > View this message in context: > http://r.789695.n4.nabble.com/Export-Results-tp2268622p2268622.html > Sent from the R help mailing list archive at Nabble.com. > > __ > R-help@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. > -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]] __ R-help@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.
[R] Export Results
Hi R users, How can I automatically export results and graphs to a file? Thanks in advance Pedro Mota Veiga -- View this message in context: http://r.789695.n4.nabble.com/Export-Results-tp2268622p2268622.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
[R] export results
Hi all, I am looping through a function for 100 time in the middle of my code, and I want to output the results from this function. Is there a way to write the results into a txt or csv fil? For example, I write the results from the first loop to the first column of a spreadsheet and the results from the second loop to the second coclumn of a spreadsheet etc. Thank you very much, Wendy -- View this message in context: http://n4.nabble.com/export-results-tp1568880p1568880.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.