Dear R-helpers, I apologize for this certainly simple question. I have the following R lines : > m = matrix(1:12 , 3 , 4); > m [,1] [,2] [,3] [,4] [1,] 1 4 7 10 [2,] 2 5 8 11 [3,] 3 6 9 12 > m1 = subset(m , m[,2]>=5); > m1 [1] 2 3 5 6 8 9 11 12 but in fact I would appreciate m1 to be also a matrix, and thus would like to get : > m1 [,1] [,2] [,3] [,4] [2,] 2 5 8 11 [3,] 3 6 9 12 ... but I don't find how to do ? (probably it is very simple ! double shame.). Thanks for any hint or pointer. Vincent
Do you mean simply m[m[,2]>=5,] ? Kristel vincent at 7d4.com wrote:> Dear R-helpers, > > I apologize for this certainly simple question. > I have the following R lines : > > > m = matrix(1:12 , 3 , 4); > > m > [,1] [,2] [,3] [,4] > [1,] 1 4 7 10 > [2,] 2 5 8 11 > [3,] 3 6 9 12 > > > m1 = subset(m , m[,2]>=5); > > m1 > [1] 2 3 5 6 8 9 11 12 > > but in fact I would appreciate m1 to be also a matrix, > and thus would like to get : > > > m1 > [,1] [,2] [,3] [,4] > [2,] 2 5 8 11 > [3,] 3 6 9 12 > > ... but I don't find how to do ? > (probably it is very simple ! double shame.). > Thanks for any hint or pointer. > Vincent > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.htmlDisclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
On Sat, 2005-11-12 at 20:24 +0100, vincent at 7d4.com wrote:> Dear R-helpers, > > I apologize for this certainly simple question. > I have the following R lines : > > > m = matrix(1:12 , 3 , 4); > > m > [,1] [,2] [,3] [,4] > [1,] 1 4 7 10 > [2,] 2 5 8 11 > [3,] 3 6 9 12 > > > m1 = subset(m , m[,2]>=5); > > m1 > [1] 2 3 5 6 8 9 11 12 > > but in fact I would appreciate m1 to be also a matrix, > and thus would like to get : > > > m1 > [,1] [,2] [,3] [,4] > [2,] 2 5 8 11 > [3,] 3 6 9 12 > > ... but I don't find how to do ? > (probably it is very simple ! double shame.). > Thanks for any hint or pointer. > VincentWhat version of R are you using? You did not indicate this in your post as you are asked to do in the posting guide. In R version 2.1.0, a matrix method was added to the subset() function, so I am guessing that you are several versions out of date. Please upgrade to the latest version, which is 2.2.0, where you will get:> subset(m, m[, 2] >= 5)[,1] [,2] [,3] [,4] [1,] 2 5 8 11 [2,] 3 6 9 12 Also, you do not need the semi-colons at the end of each line. They are only generally used if you wish to place more than one R statement on a single line. HTH, Marc Schwartz
Kristel Joossens a ??crit :> Do you mean simply m[m[,2]>=5,] ?yes. Arghh !!! Thanks to all of you for your helpful answers. Vincent
Marc Schwartz a ??crit :> In R version 2.1.0, a matrix method was added to the subset() function, > so I am guessing that you are several versions out of date. Please > upgrade to the latest version, which is 2.2.0, where you will get:I upgraded and it works fine. Thanks for the hint. Many thanks also to the authors of the function, Peter Dalgaard and prof Ripley (I suspect prof Ripley is responsible for the matrix improvment ?). Many thanks also to all the contributors to the last version of this wonderful software. Vincent