[R] median by geometric mean
ehlers at ucalgary.ca
Mon Jan 17 17:06:07 CET 2011
I've been reminded by Prof. Brian Ripley that R's
log() function will indeed handle zeros appropriately.
Apologies to S Ellison and Hadley Wickham.
On 2011-01-17 06:55, Peter Ehlers wrote:
> On 2011-01-17 02:19, S Ellison wrote:
>> Will this do?
>> x<- runif(20, 1, 100)
>> exp( median( log( x) ) )
>> S Ellison
> That's what Hadley proposed, too. It's fine for
> your example, but there is potentially a small
> problem with this method: the data must be positive.
> Since it's not unusual to see data with some zeros,
> the log() would fail.
> Depending on what type of data I was going to use
> this modification of the median for, I would consider
> modifying the (quite short) median.default function,
> with appropriate additional data checks.
> Peter Ehlers
>>>>> Skull Crossbones<witch.of.agnessi at gmail.com> 15/01/2011 16:26>>>
>> Hi All,
>> I need to calculate the median for even number of data points.However
>> instead of calculating
>> the arithmetic mean of the two middle values,I need to calculate their
>> geometric mean.
>> Though I can code this in R, possibly in a few lines, but wondering if
>> already some built in function.
>> Can somebody give a hint?
>> Thanks in advance
More information about the R-help