# [R] how to create and manage a matrix with vector of different length

zhaoxing731 zhaoxing731 at yahoo.com.cn
Mon Jan 10 11:48:02 CET 2011

```Hello
I have a data consisting of 245 counties, including the population, number of illness and the geographical information of each county. Fixing each county, I want to sort the other county by distance, which can make a 245*245 matrix with each cell is the corresponding index of the county, e.g. the 3rd row of the matrix is a vector of descending order of the 245 indices, maybe c(3,34,178,.....), means that the NO.34 county is the second closest the NO.3 county.  We can call it DISTANCE matrix.
From DISTANCE matrix, I can get a matrix POP and matrix CASE into the corresponding cell of the DISTANCE matrix respectively, by "cumsum" command and get matrix CUMPOP and matrix CUMCASE, which can explained different size circle of different center, and we can call a function element-wise
The problem, I want to restrict the cumulative population of each circle within 50% of the total population, which will make every row-vector have different length. e.g. the first row-vector have a length of 123, but the second maybe have a length of 141. I checked R_intro, it seems ragged array can do it, but I can't find any material to learn.
1.Can anyone teach me how to creat and manage a matrix with vector of different length?
2.Can anyone teach me 2 or 3 matrices call a function element wise by vectorization? e.g. for (i in 1:10) A[i]^B[i]/C[i]

Yours sincerely

ZhaoXing
Department of Health Statistics
West China School of Public Health
Sichuan University
No.17 Section 3, South Renmin Road
Chengdu, Sichuan 610041
P.R.China

__________________________________________________
¸Ï¿ì×¢²áÑÅ»¢³¬´óÈÝÁ¿Ãâ·ÑÓÊÏä?

```