Re: Error in median()

new topic     » goto parent     » topic index » view thread      » older message » newer message

Quite so.

I've reverted to my own function, which I wrote way back before the stats package was available. To use this, I changed median() in the code I'm writing to Median(). Simple enough.

--**************************************************************** 
--**********         global function Median       **************** 
--**************************************************************** 
global function Median (object oInput) 
-- Input: A sequence of atoms 
-- Output: The median of those values 
sequence sTemp 
integer	 iIndex 
 
if atom(oInput) then 
	return oInput 
end if 
 
if length(oInput) = 1 then 
	return oInput[1] 
end if 
 
sTemp = sort(oInput) 
	if IsOdd(length(sTemp)) then 
		iIndex = floor(length(sTemp) / 2) + 1 
		return sTemp[iIndex] 
	else 
		iIndex = length(sTemp) / 2 
		return  (sTemp[iIndex] + sTemp[iIndex + 1]) / 2 
	end if 
 
end function 
new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu