Skip to content

convert point data to count data

2 messages · Adrian Baddeley

#
Karla Falk writes:
You can use the command 'pixellate' in spatstat.

library(spatstat)

data(redwood)

Z <- pixellate(redwood, eps=0.1, padzero=TRUE)

df <- data.frame(x=rasterx.im(Z), y=rastery.im(Z), count=as.vector(as.matrix(Z)))



Then 'df' is the output table you wanted. To display it,



plot(Z)

with(df, text(x,y,count))



The size of the grid cells can be controlled using 'eps' (for squares of side length 'eps')

or 'dimyx' (specifying the number of rows and columns of cells).



Adrian Baddeley
#
Sorry, that should have been

df <- data.frame(x=as.vector(rasterx.im(Z)),
                         y=as.vector(rastery.im(Z)),
                         count=as.vector(as.matrix(Z)))

Adrian