qqh5011
2011-Nov-07 13:06 UTC
[R] How do I return to the row values of a matrix after computing distances
## 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!!!! qqh5011 [[alternative HTML version deleted]]
David Winsemius
2011-Nov-07 15:39 UTC
[R] How do I return to the row values of a matrix after computing distances
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. http://stackoverflow.com/questions/8036831/how-to-return-to-the-qualifying-rows-of-original-data 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