Compare 7059 with nrow(x). Looks like they do not match, it is best not to hardcode such things.
Cheers, Mike On 9 Jun 2014 05:40, "lijiaming" <lijiamingfore...@gmail.com> wrote: > Hi All, > I try to empoly Monte Carlo to find out the distribution of my data. > The code is following > library(sp) > library(rgdal) > library(raster) > x<-readOGR(".", "finance") #get one spatial file > N.list<-list() > for(i in 1:1000){ > Sample.x<-sample(1:7059,600) #the shp file includes 7059 pointsï¼and I > want get 600 of them by random sample > Point.x<-x[Sample.x,] # get 600 points > distance.x<-pointDistance(Point.x,lonlat=FALSE) #Calculate the distance > between any two points 600 > y<-distance.x/1000 # the Unit is meter, but I want it become kilometer > y<-round(y,0) # > split.point=seq(min(y),max(y),by=1) > result<-hist(y,breaks=split.point) #get the frequency of each distance > N.list[[i]]<-result$counts #put the result into the list > } > if without loop, the code is right. But the loop construct is important. > The error ls: > Error in x@coords[i, , drop = FALSE] : subscript out of bounds > > > > > > Jiaming Li > [[alternative HTML version deleted]] > > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > [[alternative HTML version deleted]]
______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.