[R] Function Error
Erik Iverson
iverson at biostat.wisc.edu
Tue Jul 22 21:15:09 CEST 2008
Please give commented, minimal, self-contained, reproducible code. In
this case, not only the function definition, but a simple example
showing *how* it does not work, and what you were expecting it to do!
Angelo Scozzarella 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
>
> ______________________________________________
> 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.
More information about the R-help
mailing list