[R] How do I return to the row values of a matrix after computing distances

David Winsemius dwinsemius at comcast.net
Mon Nov 7 16:39:54 CET 2011

On Nov 7, 2011, at 8:06 AM, qqh5011 wrote:

> ##    Package Needed
> library(fields)
> ## Assumptions
> set.seed(123)
> nsim<-5
> p<-2
> ##    Generate Random Matrix G
> G <- matrix(runif(p*nsim),nsim,p)
> ##    Set Empty Matraces dmax and dmin
> dmax<- matrix(data=NA,nrow=nsim,ncol=p)
> dmin<- matrix(data=NA,nrow=nsim,ncol=p)
> ## Loop to Fill dmax and dmin
> for(i in 1:nsim) {
> dmax[i]<- max(rdist(G[i,,drop=FALSE],G))
> dmin[i]<- min(rdist(G[i,,drop=FALSE],G[-i,])) }
> I filled the dmax and dmin with the distance values I calculated,  
> but what I really want to fill them with are the rows in G. What  
> should I do? I tried "which" function but it did not work. Thank you  
> in advance!!!!

Dear qq5011 ... AKA user1033763;

The practice of cross-posting questions to StackOverFlow and rhelp  
within hours of each other is deprecated, at least on on rhelp.


If you don't get an answer within some reasonable interval (measured  
in days, not hours) then feel free to post a follow-up ... with  
citation of the first posting.

> qqh5011
> 	[[alternative HTML version deleted]]

Posting in HTML is likewise deprecated. Please read the Posting Guide  
were both of these issues and many other sensible requests for  
professional behavior are detailed

> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html

> and provide commented, minimal, self-contained, reproducible code.

(You did do that, and please continue to do so.)

David Winsemius, MD
West Hartford, CT

More information about the R-help mailing list