Skip to content
Prev 326895 / 398502 Next

Replacing values of a matrix with values from corresponding rows of another matrix

This should also work:
[,1]  [,2]  [,3]  [,4]  [,5] [,6]
[1,] FALSE FALSE  TRUE FALSE FALSE TRUE
[2,]  TRUE  TRUE FALSE  TRUE  TRUE TRUE
[3,] FALSE  TRUE  TRUE FALSE FALSE TRUE
[4,]  TRUE  TRUE FALSE  TRUE FALSE TRUE
[,1] [,2] [,3] [,4] [,5] [,6]
[1,]    0    0    4    0    0    1
[2,]    2    2    0    1    0    2
[3,]    0    5    0    0    0    1
[4,]    3    1    0    5    0    4

-------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77840-4352


-----Original Message-----
From: r-help-bounces at r-project.org
[mailto:r-help-bounces at r-project.org] On Behalf Of Laura Cisneros
Sent: Monday, July 15, 2013 8:31 AM
To: Blaser Nello
Cc: r-help at r-project.org
Subject: Re: [R] Replacing values of a matrix with values from
corresponding rows of another matrix

Great! Thank you, Nello. It works on my larger matrices.


On Mon, Jul 15, 2013 at 2:40 AM, Blaser Nello
<nblaser at ispm.unibe.ch> wrote:

            
sample(original[i,original[i,]!=0])
sample(original[i,original[i,]!=0])
[mailto:r-help-bounces at r-project.org]
corresponding
a
matrix.
matrix(c(0,0,4,0,0,1,2,2,12,1,0,2,0,5,0,0,10,1,3,1,0,5,0,4),byrow=TR
UE,nrow=4,ncol=6)
randomized
matrix(c(0,0,12,0,0,1,2,2,0,5,10,2,0,1,4,0,0,1,3,5,0,1,0,4),byrow=TR
UE,nrow=4,ncol=6)
non-zero
values from
row 1 I
matrix) with 4
greatly
Connecticut