Re: [R] help with executing instruction every i-th run of loop

From: Uwe Ligges <ligges_at_statistik.uni-dortmund.de>
Date: Thu, 17 May 2007 16:59:30 +0200

Mark W Kimpel wrote:
> I am running a very long loop and would like to save intermediate
> results in case of a system or program crash. Here is the skeleton of
> what my code would be:
>
> for (i in 1:zillion)
> {
> results[[i]]<-do.something.function()
> if (logical.test(i)) {save(results, "results.tmp")}
> }
>
> logical.test would test to see if i/1000 has no remainder. What R
> function would test that?

    !(i %% 1000)

Uwe Ligges

> Is there an even better way to address my need?
>
> Thanks,
> Mark



R-help_at_stat.math.ethz.ch 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. Received on Thu 17 May 2007 - 15:09:06 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 17 May 2007 - 15:31:23 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.