[R] Function Error

Sarah Goslee sarah.goslee at gmail.com
Tue Jul 22 21:30:23 CEST 2008


At a first guess, because you are missing a right paren in thereturn()
statement of the final else section.

Otherwise, we'd need to know about what "doesn't work" means -
what is x supposed to be? What do you want the function to do?
What error messages are you getting?

You haven't provided any of the information we need to actually
help you. The posting guide describes what you should include,
and is linked at the end of every message.

Sarah

On Tue, Jul 22, 2008 at 2:51 PM, Angelo Scozzarella
<angeloscozzarella at tiscali.it> wrote:
> 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
>


-- 
Sarah Goslee
http://www.functionaldiversity.org



More information about the R-help mailing list