[R] the matrix of rows with specific row sums

Berton Gunter gunter.berton at gene.com
Tue Nov 22 23:20:34 CET 2005


Standard caution: == should not be used for comparison of floating point
numbers. See ?all.equal  and ?identical. See also the Green Book (Chambers:
PROGRAMMING WITH DATA). Sometimes what you think are integers may be floats,
too, as numerous postings to this list have shown.

-- Bert Gunter
Genentech Non-Clinical Statistics
South San Francisco, CA
 
"The business of the statistician is to catalyze the scientific learning
process."  - George E. P. Box
 
 

> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch 
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Seth Falcon
> Sent: Tuesday, November 22, 2005 1:38 PM
> To: r-help at stat.math.ethz.ch
> Subject: Re: [R] the matrix of rows with specific row sums
> 
> On 22 Nov 2005, kaniovsk at wsr.ac.at 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
> 
> ______________________________________________
> 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.html
>




More information about the R-help mailing list