On May 28, 2010, at 12:30 PM, UM wrote:
hi,
I have been trying to do this in R (have implemented it in Excel)
but I have
been using a very inefficent way (loops etc.). I have matrix A
(columns are
years and ages are rows) and matrix B (columns are birth yrs and
rows are
ages)
I would like to first turn matrix A into matrix B
> catrow <- function(A, rn) c(rep("0", 3-rn), A[rn,],rep("0",
(2+rn)-3) )
> matrix(sapply(1:3, function(x) catrow(A, x)) , ncol=2*ncol(A)-1,
byrow=TRUE)
[,1] [,2] [,3] [,4] [,5]
[1,] "0" "0" "a" "b" "c"
[2,] "0" "d" "e" "f" "0"
[3,] "g" "h" "i" "0" "0"
And then I would like to convert matrix B back again to the original
matrix
A.
Left as an exercise for the reader.
(I have left out details of steps) but this is the gist of what I
want to
do. Can anyone please give any insights?
David Winsemius, MD
West Hartford, CT
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.