[R] permutation of rows of a matrix

John Fox jfox at mcmaster.ca
Sun Apr 16 14:14:13 CEST 2006


Dear Manuel,

I do understand your point of view, and think that it is reasonable, but in
this case, I disagree. 

It wouldn't hurt to have an example in ?sample of using a permutation to
index a matrix, but this is one of many uses of permutations and it is not
possible to show or even to anticipate all of them. 

To use a programming environment like R effectively, it's necessary to
acquire some basic facility with the language (such as an understanding of
how indexing works), and it's much more efficient to acquire this facility
by reading a manual or book than through help pages. For example, the
Introduction to R manual that comes with R has a section on indexing arrays,
and most introductory books on R, including free ones, have more detailed
explanations of the subject.

Regards,
 John

--------------------------------
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario
Canada L8S 4M4
905-525-9140x23604
http://socserv.mcmaster.ca/jfox 
-------------------------------- 

> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch 
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Manuel 
> López-Ibáñez
> Sent: Sunday, April 16, 2006 4:52 AM
> To: r-help at stat.math.ethz.ch
> Subject: Re: [R] permutation of rows of a matrix
> 
> Dear John,
> 
> I understand what you mean. However, when someone is learning 
> R for the first time or have little experience, such examples 
> help to understand the connection of different parts of the language.
> 
> Moreover, things that make sense once you know them, can be 
> difficult to relate in the first place. For example, it would 
> be interesting to know how many new R users don't know that 
> there is a manual page for "[".
> 
> I hope you can understand my point of view (you may disagree, though.)
> 
> Regards,
> 	Manuel.
> 
> 
> John Fox wrote:
> > Dear Manuel,
> > 
> > Although ?sample doesn't specifically describe permuting 
> the rows of a 
> > matrix, it does say that "sample(x) generates a random 
> permutation of 
> > the elements of x (or 1:x)." Indexing the rows of the matrix by a 
> > permutation of 1:x (where x is the number of rows) doesn't 
> seem to be much of a leap.
> > 
> > Regards,
> >  John
> > 
> > --------------------------------
> > John Fox
> > Department of Sociology
> > McMaster University
> > Hamilton, Ontario
> > Canada L8S 4M4
> > 905-525-9140x23604
> > http://socserv.mcmaster.ca/jfox
> > --------------------------------
> > 
> > 
> >>-----Original Message-----
> >>From: r-help-bounces at stat.math.ethz.ch 
> >>[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Manuel 
> >>López-Ibáñez
> >>Sent: Saturday, April 15, 2006 9:44 AM
> >>To: r-help at stat.math.ethz.ch
> >>Subject: Re: [R] permutation of rows of a matrix
> >>
> >>help(sample) does not say anything about randomly permuting 
> the rows 
> >>of a matrix M by using M[sample(m,m),]. Perhaps it could be 
> added as 
> >>an example of use.
> >>
> >>John Fox wrote:
> >>
> >>>Dear Jose,
> >>>
> >>>M[sample(m, m),] will randomly permute the rows of M. [You 
> probably 
> >>>could have figured this out via help.search("permutation"), which 
> >>>would have led you to sample().]
> >>>
> >>>Regards,
> >>> John
> >>>
> >>>--------------------------------
> >>>John Fox
> >>>Department of Sociology
> >>>McMaster University
> >>>Hamilton, Ontario
> >>>Canada L8S 4M4
> >>>905-525-9140x23604
> >>>http://socserv.mcmaster.ca/jfox
> >>>--------------------------------
> >>>
> >>>
> >>>
> >>>>-----Original Message-----
> >>>>From: r-help-bounces at stat.math.ethz.ch 
> >>>>[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of javargas
> >>>>Sent: Saturday, April 15, 2006 7:53 AM
> >>>>To: r-help at stat.math.ethz.ch
> >>>>Subject: [R] permutation of rows of a matrix
> >>>>
> >>>>How can I generate a random permutation between rows of a
> >>
> >>matrix M (of
> >>
> >>>>m rows and n columns)?
> >>>>
> >>>>Thanks for your help,
> >>>>
> >>>>Jose
> >>>>
> >>>>______________________________________________
> >>>>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
> >>>
> >>>
> >>>______________________________________________
> >>>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
> >>>
> >>
> >>		
> >>______________________________________________
> >>LLama Gratis a cualquier PC del Mundo. 
> >>Llamadas a fijos y móviles desde 1 céntimo por minuto. 
> >>http://es.voice.yahoo.com
> >>
> >>______________________________________________
> >>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
> > 
> > 
> > 
> 
> 	
> 	
> 		
> ______________________________________________
> LLama Gratis a cualquier PC del Mundo. 
> Llamadas a fijos y móviles desde 1 céntimo por minuto. 
> http://es.voice.yahoo.com
> 
> ______________________________________________
> 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