zhaoxing731
2011-Jan-10 10:48 UTC
[R] how to create and manage a matrix with vector of different length
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] Thank you in advance 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 __________________________________________________ ?????????????????????????????
Apparently Analagous Threads
- how to use "apply" function partial to each vector of a matrix
- how to coerce part of each column of a matrix to a vector and merge them
- How can we make a vector call a function element-wise efficiently?
- matrices call a function element-wise
- how to return multipy matrix in a function