Re: [R] which() and value replacement in a matrix

2004-10-11 Thread Petr Pikal
the best, Patrick - Original Message - From: Liaw, Andy [EMAIL PROTECTED] To: 'Patrick Giraudoux' [EMAIL PROTECTED]; r-help [EMAIL PROTECTED] Sent: Saturday, October 09, 2004 3:00 PM Subject: RE: [R] which() and value replacement in a matrix Use the index vector directly, rather

[R] which() and value replacement in a matrix

2004-10-09 Thread Patrick Giraudoux
Hi, I cannot go through the archives with which() as key-word... so common. Though I am sure to have seen something about this subject in the past could somebody put me on the track. I have a matrix (actually a data.frame) in which I would replace the non-null values by 1. I tried the

RE: [R] which() and value replacement in a matrix

2004-10-09 Thread Liaw, Andy
Use the index vector directly, rather than breaking it up: x - matrix(sample(30), 10, 3) idx - which(x 25, arr.ind=TRUE) idx row col [1,] 6 1 [2,] 9 1 [3,] 4 2 [4,] 6 2 [5,] 4 3 x[idx] - 999 x [,1] [,2] [,3] [1,]7 14 16 [2,] 20 248 [3,] 17

Re: [R] which() and value replacement in a matrix

2004-10-09 Thread Patrick Giraudoux
() and value replacement in a matrix Use the index vector directly, rather than breaking it up: x - matrix(sample(30), 10, 3) idx - which(x 25, arr.ind=TRUE) idx row col [1,] 6 1 [2,] 9 1 [3,] 4 2 [4,] 6 2 [5,] 4 3 x[idx] - 999 x [,1] [,2] [,3

RE: [R] which() and value replacement in a matrix

2004-10-09 Thread Liaw, Andy
] Sent: Saturday, October 09, 2004 3:00 PM Subject: RE: [R] which() and value replacement in a matrix Use the index vector directly, rather than breaking it up: x - matrix(sample(30), 10, 3) idx - which(x 25, arr.ind=TRUE) idx row col [1,] 6 1 [2,] 9 1 [3,] 4