[R] Ignore errors and proceed to next

Frede Aakmann Tøgersen frtog at vestas.com
Fri Feb 14 10:35:12 CET 2014




So you still want to do these distribution tests even though you have been warned not to?

Yours sincerely / Med venlig hilsen

Frede Aakmann Tøgersen
Specialist, M.Sc., Ph.D.
Plant Performance & Modeling

Technology & Service Solutions
T +45 9730 5135
M +45 2547 6050
frtog at vestas.com

Company reg. name: Vestas Wind Systems A/S
This e-mail is subject to our e-mail disclaimer statement.
Please refer to www.vestas.com/legal/notice
If you have received this e-mail in error please contact the sender. 

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
> On Behalf Of Alaios
> Sent: 14. februar 2014 10:14
> To: R-help at r-project.org
> Subject: [R] Ignore errors and proceed to next
> Hi all,
> I have a very large number of vectors that I want first to look fast which
> distribution might be considered candidate for fitting.
> I made a simple loop that checks for all vector (the code below is for one
> vector and being called for each vector separately). If a good fit is found this
> is dumped to a txt file so to allow me later on, see results
> distList<-c("norm","exp","gamma","lnorm")
>     for (dist in distList) {
>         if (gofstat(fitdist(onVector,distr=dist))$kstest =="not rejected"){
>         # keep it
>           out<-capture.output(gofstat(fitdist(onVector,distr=distr))$ks)
>           print(sprintf("Saving to file %s ",filename))
>           cat(out,file=paste(filename,".txt",sep=""),sep="\n",append=TRUE)
>         }
>     }
> the major problem is that these for loops return errors (sometimes for a
> given vector a specific distribution does not make sense or the vector might
> be zero or containing only many times the same element)    . The easiest
> would be in errors and warning just move to the next element of the for
> loop.
> Something like that
> for ()
> {
>  if error==skip to next element
>  else do normal stuff
> }
> how I can do that in R?
> Regards
> Alex
> 	[[alternative HTML version deleted]]

More information about the R-help mailing list