Re: [R] matrix indexing and update

2008-11-05 Thread Jorge Ivan Velez
Dear Murali, Here is one way: set.seed(123) a <- matrix(abs(rnorm(100)), 10) b <- rnorm(10) apply(a,2,function(x) ifelse(b>quantile(b,probs=0.75),-x,x)) HTH, Jorge On Wed, Nov 5, 2008 at 11:30 AM, <[EMAIL PROTECTED]> wrote: > Folks, > > I have a matrix: > > set.seed(123) > a <- matrix(rn

Re: [R] matrix indexing and update

2008-11-05 Thread Dimitris Rizopoulos
you almost have it, e.g., check the following: set.seed(123) a <- matrix(rnorm(100), 10) b <- rnorm(10) ind <- b > quantile(b, 0.75) a[ind, ] <- -a[ind, ] a I hope it helps. Best, Dimitris [EMAIL PROTECTED] wrote: Folks, I have a matrix: set.seed(123) a <- matrix(rnorm(100), 10) And a v

[R] matrix indexing and update

2008-11-05 Thread murali . menon
Folks, I have a matrix: set.seed(123) a <- matrix(rnorm(100), 10) And a vector: b <- rnorm(10) Now, I want to switch the signs of those rows of a corresponding to indices in b whose values exceed the 75 %-ile of b which(b > quantile(b)[4]) [1] 2 6 10 so I want, in effect: a[2, ] <- -a[2,