Re: [R] Function Error

From: anna freni sterrantino <annafreni_at_yahoo.it>
Date: Tue, 22 Jul 2008 20:04:16 +0000 (GMT)


Hi Angelo,
please read the posting guide, before posting!

Anyway, for general rule, if you want to see what's going on in a function at each step, it may be helpful  to install library("debug")
that has very useful functions as "mtrace" that my resolve your problem.

 Cheers
Anna

Hi,

Why this function doesn't work?

function (x)
{

     if (is.factor(x)) {
         if (!is.ordered(x)) {
             warning("La mediana non si puo' calcolare!!!")
             return(NA)

}
me <- median(unclass(x)) if (me - floor(me) != 0) { warning("Mediana indeterminata") return(NA)
}
else { levels(x)[me]
}
}

    else if(class(x)=="histogram"){
    N<-sum(x$counts)
    cl<-min(which(cumsum(x$counts)>=N/2))     return(x$breaks[cl]+
    (N/2-sum(x$counts[1:(cl-1)]))/(x$densit[cl]*N)      } else median(x)
}

thanks

Angelo Scozzarella



R-help_at_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.

Anna Freni Sterrantino
Ph.D Student
Depatment of Statistics
University of Bologna, Italy
via Belle arti 41, 40124 Bo

      Posta, news, sport, oroscopo: tutto in una sola pagina. [[elided Yahoo spam]]
www.yahoo.it/latuapagina

        [[alternative HTML version deleted]]



R-help_at_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. Received on Tue 22 Jul 2008 - 20:08:31 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 Tue 22 Jul 2008 - 20:34:03 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.

list of date sections of archive