**R Video tutorial for Spatial Statistics**, and kindly contributed to R-bloggers)

**spatstat**.

The problem was that I only had a point shapefile, so I googled a way to transform a shapefile into a ppp object (which is the point pattern object used by

**spatstat**).

I found a method that involves the use of

`as.ppp(X)`

to transform both `spatial points`

and `spatial points data frames`

into `ppp`

objects. The problem is when I tested with my dataset I received an error and I was not able to perform the transformation.
So I decided to do it myself and I now want to share my two lines of code for doing it, maybe someone has has encountered the same problem and does not know how to solve it. Is this not the purpose of these blogs?

First of all, you need to create the window for the `ppp`

object, which I think it is like a bounding box. To do that you need to use the function `owin`

.

This functions takes 3 arguments: `xrange`

, `yrange`

and `units`

.

Because I assumed you need to give `spatstat`

a sort of bounding box for your data, I imported a polygon shapefile with the border of my area for creating the window.

The code therefore looks like this:

`library(raster)`

library(spatstat)

`border <- shapefile("Data/britain_UTM.shp")`

`window <- owin(xrange=c(bbox(border[1,1],bbox(border[1,2]),`

yrange=c(bbox(border)[2,1],bbox(border)[2,2]),

unitname=c("metre","metres"))

Then I loaded my datafile (i.e. WindData) and used the window object to transform it into a point pattern object, like so:

`WindData <- shapefile("Data/WindMeanSpeed.shp")`

` WindDataPP <- ppp([email protected][,1],`

[email protected][,2],

[email protected]$MEAN,

window=window)

Now I can use all the functions available in `spatstat`

to explore my dataset.

`summary(WindDataPP)`

@fveronesi_phd

**leave a comment**for the author, please follow the link and comment on their blog:

**R Video tutorial for Spatial Statistics**.

R-bloggers.com offers

**daily e-mail updates**about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...