_______________________________________________________________________________________
There is also rowSums (and colSums) which does the same thing without needing apply: m[rowSums(m) == 2, ] Subject to Bert Gunter's caveat about comparing floating point numbers for equality, of course. -- Hong Ooi Senior Research Analyst, IAG Limited 388 George St, Sydney NSW 2000 (02) 9292 1566 -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Seth Falcon Sent: Wednesday, 23 November 2005 8:38 AM To: [email protected] Subject: Re: [R] the matrix of rows with specific row sums On 22 Nov 2005, [EMAIL PROTECTED] wrote: > I am just starting with R and have the following problem: given a > matrix of ones and zeroes, say > > mdim=4 > m<-matrix(round(runif(mdim^mdim)),mdim,mdim) > > how to construct the matrix of those rows of m, whose elements sum > to 2. Contrary to the random matrix above, the actual matrix always > has at least one such row. Untested, but I think you want something like: idx <- apply(m, 1, sum) == 2 ans <- m[idx, ] + seth ______________________________________________ [email protected] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html _______________________________________________________________________________________ The information transmitted in this message and its attachme...{{dropped}} ______________________________________________ [email protected] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
