[R] Weighted median for matrices

Jakob Petersen jakob.petersen at qmul.ac.uk
Thu Mar 31 12:57:33 CEST 2005



I am working with a matrix (x),

where rows are non-overlapping geographical areas (postcodes; here 
denoted with letter row names),

and columns are income bands with a central value (e.g. £7.5k, here 
denoted x1,x2, etc.).

The data are counts (how many households with 0-5k pa, 5-10k pa?, etc.)

 

I would like to summarise this data set.

First row-wise as suggested by Henrik Bengtsson 
(www.maths.lth.se/help/R/R.classes/ 
<http://www.maths.lth.se/help/R/R.classes/>  ), example:

 

library (R.basic)

x<-cbind(x1=3,x2=c(4:1,2:5))

dimnames(x)[[1]]<-letters[1:8]

w<-c(1,2)

wm <- apply(x, MARGIN=1, FUN=weighted.median, w=w, na.rm=TRUE)

wm

 

QUESTION
Secondly, I would like to aggregate rows (postcodes) into bigger units 
according additional factor vectors (higher administrative order or 
environmental attributes).

I would be grateful for ideas to how I can achieve this in our R.

 

Jakob

 

Software:

R ver 2.01 (Windows)

R.basic ver 0.59

 

Jakob Petersen

GISc student (MSc)

Birkbeck, University of London




More information about the R-help mailing list