まず、あなたのRコードは書かれたとおりに動作しません。クリーンなセッションにコピー&ペーストすることをお勧めします。また、エラーが発生した場合は、構文エラーを修正したり、アドオンライブラリを実行するまで追加してください。
つまり、私は、data.frame
の2次元数値座標で終わると仮定します。だから、ビンニングとカウントの目的のために、そのようなデータがあれば、私はそのようなデータセットをシミュレートする自由を取った。これがあなたのデータの関連する側面を捕らえない場合は、私を修正してください。
## Skip this line if you are the OP, and substitute the real data instead.
data<-data.frame(LATITUDE=runif(100,1,100),LONGITUDE=runif(100,1,100));
## Add the latitudes and longitudes between which each observation is located
## You can substitute any number of breaks you want. Or, a vector of fixed cutpoints
## LATgrid and LONgrid are going to be factors. With ugly level names.
data$LATgrid<-cut(data$LATITUDE,breaks=10,include.lowest=T);
data$LONgrid<-cut(data$LONGITUDE,breaks=10,include.lowest=T);
## Create a single factor that gives the lat,long of each observation.
data$IDgrid<-with(data,interaction(LATgrid,LONgrid));
## Now, create another factor based on the above one, with shorter IDs and no empty levels
data$IDNgrid<-factor(data$IDgrid);
levels(data$IDNgrid)<-seq_along(levels(data$IDNgrid));
## If you want total grid-cell count repeated for each observation falling into that grid cell, do this:
data$count<- ave(data$LATITUDE,data$IDNgrid,FUN=length);
## You could have also used data$LONGITUDE, doesn't matter in this case
## If you want just a table of counts at each grid-cell, do this:
aggregate(data$LATITUDE,data[,c('LATgrid','LONgrid','IDNgrid')],FUN=length);
## I included the LATgrid and LONgrid vectors so there would be some
## sort of descriptive reference accompanying the anonymous numbers in IDNgrid,
## but only IDNgrid is actually necessary
## If you want a really minimalist table, you could do this:
table(data$IDNgrid);
どのパッケージを使用していますか? –
@HongOoi私はそれが 'sp'だと信じています。 – agstudy
これはあなたを始めさせるかもしれません:[Rを使ってグリッドにポイントを集める](http://gis.stackexchange.com/a/48434/9803) – Ben