Re: [R] removing the rows with negative elements

2010-01-05 Thread faridamsb
Thank you! On Jan 6, 2010 12:31am, Peter Ehlers wrote: > x[apply(x,1,function(x)all(x>=0)),] > -Peter Ehlers > Simon Blomberg wrote: > x[-which(x > but I'm sure someone will suggest an easier way. > Simon. > On Wed, 2010-01-06 at 05:13 +, farida...@gmail.com wrote: > Hello A

[R] removing the rows with negative elements

2010-01-05 Thread faridamsb
Hello All, I would like to remove the entire row, if there is any negative element in that row. What is the best way to do that? For example, x<-matrix(c(2,-1,-2,3,5,6,-3,7,4,2,1,0), 4, 3) the returning matrix should look like [,1] [,2] [,3] [1,] 2 5 4 [2,] 3 7 0 Thank you in advance, FM

[R] Removing replicated rows

2009-12-30 Thread faridamsb
Dear All, I have a matrix like X and need to create a new matrix based on the vector m which gives the number of replicates for each unique row. The resulting matrix should look like y. > x x1 x2 [1,] 2 0.5 [2,] 2 0.5 [3,] 2 0.5 [4,] 6 1.0 [5,] 6 1.0 [6,] 6 1.0 [7,] 1 1.5 [8,] 1 1.5 [9,] 1 1.

[R] apply a function over a factor

2009-12-29 Thread faridamsb
Dear R experts, I would like to substitute the values of a vector, say A, with the average values taken over a factor For example, lets assume A [1] 1 2 3 4 5 6 7 8 9 10 B [1] 1 2 2 4 4 4 7 7 7 7 Levels: 1 2 4 7 I need to have 1.0 2.5 2.5 5.0 5.0 5.0 8.5 8.5 8.5 8.5 8.5 Thank you