[R] Finding the median

elliot.welch at virgin.net elliot.welch at virgin.net
Mon Mar 12 12:15:06 CET 2012


Hi just a quick question in which I must use the "function and return" part of R.

If I was asked to define a function called "median" where the function has a single argument x and returns the median value of a vector. How would I go about saying the median = element x in terms of n (say (n + 1)/2 or whatever it would be) if there is an even amount of elements, or x in terms of n (with a different way of saying how many n) if there is an odd amount of elements? 

Much appreciated 

elliot.welch at virgin.net 
Sent from my BlackBerry® smartphone


More information about the R-help mailing list