Skip to content
Prev 58893 / 398502 Next

(no subject)

Please read the posting guide that tells you to a) use a meaningful
subject line b) give a reproducible example if you can c) read the
manuals and help files first

If you have a vector (not a list) of numbers, say x, and you want to
center it on the median you can do

x <- c(1,2,3,4,5)

Then x - median(x) will give you the deviation of x from its median.
Note that operations in R is vectorised, so you do not need to to do
something like "for(i in 1:5) y[i] <- x[i] - median(x)".

Next you want to square this deviation and sum over all elements.

d <- x - median(x)
sum( d^2 )

Or you can do it in one line as  "sum( (x - median(x))^2 )"
On Thu, 2004-11-11 at 16:28, Wei Yang wrote: