OpenSauce
OpenSauce

Reputation: 354

"Error in as.double(y) : cannot coerce type 'closure' to vector of type 'double'" when I try to measure the pairwise distances

I am trying to generate a cluster pattern process using spatstat, and then calculate the distances between points using the pairdist command. I initially created a function called nclust using the code:

nclust <- function(x0, y0, radius, n) 
{return(runifdisc(n, radius, centre=c(x0, y0)))
}

Then I created an object to contain the plot:

c1<-plot(rPoissonCluster(5, 0.2, nclust, radius=0.2, n=10))

Output to the plot command for Poisson Clustering in Spatstat

However, when I try to calculate the distances between points using pairdist like so:

pairdist(c1)

I recieve the error:

 Error in as.double(y) : 
 cannot coerce type 'closure' to vector of type 'double'

I understand this may be because c1 is a function, how do I calculate the distances between these points? Is it possible to add a scale to the x and y axis of the plot so that I have actual distance values?

Many thanks!

Upvotes: 0

Views: 297

Answers (1)

Ege Rubak
Ege Rubak

Reputation: 4507

You should assign the value of the cluster process to c1 and then plot it afterwards:

c1<- rPoissonCluster(5, 0.2, nclust, radius=0.2, n=10)
plot(c1)

The result is a planar point pattern of class ppp and the plot command is dispatched to plot.ppp. In your original command you are saving the result of the plot. This plot command returns a function that can be used to make a new plot with the same plotting options (characters, colours, etc.).

Upvotes: 1

Related Questions