[R] mean on a table
Petr Pikal
petr.pikal at precheza.cz
Fri Jan 12 07:49:12 CET 2007
Hi
On 11 Jan 2007 at 23:11, Farrel Buchinsky wrote:
Date sent: Thu, 11 Jan 2007 23:11:00 -0500
From: "Farrel Buchinsky" <fjbuch at gmail.com>
To: "Peter Dalgaard" <p.dalgaard at biostat.ku.dk>
Copies to: r-help at stat.math.ethz.ch
Subject: Re: [R] mean on a table
> Not that I know of.
> When I get back to the office I will check it out.
> I certainly do not recall having created one.
> I wonder if a library I am working with maybe created a mean function.
> How do I figure out if I have a loose cannon mean function on the run
> in my system?
easiest way would by to type
> mean
function (x, ...)
UseMethod("mean")
<environment: namespace:base>
or
> mean.default
function (x, trim = 0, na.rm = FALSE, ...)
{
if (!is.numeric(x) && !is.complex(x) && !is.logical(x)) {
warning("argument is not numeric or logical: returning NA")
return(as.numeric(NA))
}
if (na.rm)
x <- x[!is.na(x)]
trim <- trim[1]
n <- length(x)
if (trim > 0 && n > 0) {
if (is.complex(x))
stop("trimmed means are not defined for complex data")
if (trim >= 0.5)
return(stats::median(x, na.rm = FALSE))
lo <- floor(n * trim) + 1
hi <- n + 1 - lo
x <- sort.int(x, partial = unique(c(lo, hi)))[lo:hi]
n <- hi - lo + 1
}
.Internal(mean(x))
}
<environment: namespace:base>
and this shall be the result.
HTH
Petr
>
> On 1/11/07, Peter Dalgaard <p.dalgaard at biostat.ku.dk> wrote:
> > Farrel Buchinsky wrote:
> > > Please suggest areas that I should troubleshoot. This command used
> > > to give me an answer and now it gives me an error.
> > >
> > >> mean(no.genot,na.rm=T)
> > >>
> > > Error in tapply(x, by, sum, na.rm = TRUE) :
> > > arguments must have same length
> > > I tried removing the na.rm=T)
> > >
> > >> mean(no.genot)
> > >>
> > > Error in `names<-.default`(`*tmp*`, value = c("by.1", "by.0")) :
> > > attempt to set an attribute on NULL
> > >
> > > The structure of my table is as follows.
> > >
> > >> str(no.genot)
> > >>
> > > table [, 1:467] 0.000 0.261 0.315 0.274 0.349 ...
> > > - attr(*, "dimnames")=List of 1
> > > ..$ : chr [1:467] "NC" "RP138" "RP139" "RP140" ...
> > >
> > > Strangely enough
> > >
> > >> mean(no.genot[1:467])
> > >>
> > > [1] 0.2426167
> > >
> > > That seems to work.
> > >
> > Have you perhaps a stray mean() or mean.table() function lying
> > around?
> >
> > Doesn't look like it would normally happen:
> >
> > > tb <- as.table(as.double(1:10))
> > > str(tb)
> > table [, 1:10] 1 2 3 4 5 6 7 8 9 10
> > - attr(*, "dimnames")=List of 1
> > ..$ : chr [1:10] "A" "B" "C" "D" ...
> > > mean(tb)
> > [1] 5.5
> >
> >
> >
> >
>
>
> --
> Farrel Buchinsky
> Mobile: (412) 779-1073
>
> ______________________________________________
> 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.
Petr Pikal
petr.pikal at precheza.cz
More information about the R-help
mailing list