Re: [R] update matrix with subset of it where only row names match

2007-11-15 Thread Martin Waller
jim holtman wrote: > Lets take a look at your solution: > >> mat1 <- matrix(0, nrow=10, ncol=3) >> dimnames(mat1) <- list(paste('row', 1:10, sep=''), LETTERS[1:3]) >> mat2 <- matrix(1:3, ncol=1, dimnames=list(c('row3', 'row7', 'row5'), "B")) >> mat2 > B > row3 1 > row7 2 > row5 3 >> mat1[rown

Re: [R] update matrix with subset of it where only row names match

2007-11-13 Thread jim holtman
Lets take a look at your solution: > mat1 <- matrix(0, nrow=10, ncol=3) > dimnames(mat1) <- list(paste('row', 1:10, sep=''), LETTERS[1:3]) > mat2 <- matrix(1:3, ncol=1, dimnames=list(c('row3', 'row7', 'row5'), "B")) > mat2 B row3 1 row7 2 row5 3 > mat1[rownames(mat2)%in%rownames(mat1),"B"]=ma

Re: [R] update matrix with subset of it where only row names match

2007-11-13 Thread Martin Waller
jim holtman wrote: > Here is one way of doing it that uses the row and column names: > >> # create test data >> mat1 <- matrix(0, nrow=10, ncol=3) >> dimnames(mat1) <- list(paste('row', 1:10, sep=''), LETTERS[1:3]) >> mat2 <- matrix(1:3, ncol=1, dimnames=list(c('row3', 'row7', 'row5'), "B")) >> ma

Re: [R] update matrix with subset of it where only row names match

2007-11-12 Thread jim holtman
Here is one way of doing it that uses the row and column names: > # create test data > mat1 <- matrix(0, nrow=10, ncol=3) > dimnames(mat1) <- list(paste('row', 1:10, sep=''), LETTERS[1:3]) > mat2 <- matrix(1:3, ncol=1, dimnames=list(c('row3', 'row7', 'row5'), "B")) > mat2 B row3 1 row7 2 row5

[R] update matrix with subset of it where only row names match

2007-11-12 Thread Martin Waller
I guess this has a simple solution: I have matrix 'mat1' which has row and column names, e.g.: A B C row10 0 0 row20 0 0 rown0 0 0 I have a another matrix 'mat2', essentially a subset of 'mat1' where the rownames are all i