as.ppp: Convert Data To Class ppp

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/ppp.R

Description

Tries to coerce any reasonable kind of data to a spatial point pattern (an object of class "ppp") for use by the spatstat package).

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
  as.ppp(X, ..., fatal=TRUE)

  ## S3 method for class 'ppp'
as.ppp(X, ..., fatal=TRUE)

  ## S3 method for class 'psp'
as.ppp(X, ..., fatal=TRUE)

  ## S3 method for class 'quad'
as.ppp(X, ..., fatal=TRUE)

  ## S3 method for class 'matrix'
as.ppp(X, W=NULL, ..., fatal=TRUE)

  ## S3 method for class 'data.frame'
as.ppp(X, W=NULL, ..., fatal=TRUE)

  ## S3 method for class 'influence.ppm'
as.ppp(X, ...)

  ## Default S3 method:
as.ppp(X, W=NULL, ..., fatal=TRUE)

Arguments

X

Data which will be converted into a point pattern

W

Data which define a window for the pattern, when X does not contain a window. (Ignored if X contains window information.)

...

Ignored.

fatal

Logical value specifying what to do if the data cannot be converted. See Details.

Details

Converts the dataset X to a point pattern (an object of class "ppp"; see ppp.object for an overview).

This function is normally used to convert an existing point pattern dataset, stored in another format, to the "ppp" format. To create a new point pattern from raw data such as x,y coordinates, it is normally easier to use the creator function ppp.

The function as.ppp is generic, with methods for the classes "ppp", "psp", "quad", "matrix", "data.frame" and a default method.

The dataset X may be:

In the last three cases, we need the second argument W which is converted to a window object by the function as.owin. In the first four cases, W will be ignored.

If X is a line segment pattern (an object of class psp) the point pattern returned consists of the endpoints of the segments. If X is marked then the point pattern returned will also be marked, the mark associated with a point being the mark of the segment of which that point was an endpoint.

If X is a matrix or data frame, the first and second columns will be interpreted as the x and y coordinates respectively. Any additional columns will be interpreted as marks.

The argument fatal indicates what to do when W is missing and X contains no information about the window. If fatal=TRUE, a fatal error will be generated; if fatal=FALSE, the value NULL is returned.

In the spatial library, a point pattern is represented in either of the following formats:

where x and y are vectors of equal length giving the point coordinates, and xl, xu, yl, yu are numbers giving the dimensions of a rectangular window.

Point pattern datasets can also be created by the function ppp.

Value

An object of class "ppp" (see ppp.object) describing the point pattern and its window of observation. The value NULL may also be returned; see Details.

Author(s)

\spatstatAuthors

See Also

ppp, ppp.object, as.owin, owin.object

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
 xy <- matrix(runif(40), ncol=2)
 pp <- as.ppp(xy, c(0,1,0,1))

 # Venables-Ripley format
 # check for 'spatial' package
 spatialpath <- system.file(package="spatial")
 if(nchar(spatialpath) > 0) {
   require(spatial)
   towns <- ppinit("towns.dat")
   pp <- as.ppp(towns) # converted to our format
   detach(package:spatial)
 }

 xyzt <- matrix(runif(40), ncol=4)
 Z <- as.ppp(xyzt, square(1))

Example output

Loading required package: nlme
Loading required package: rpart

spatstat 1.51-0       (nickname: 'Poetic Licence') 
For an introduction to spatstat, type 'beginner' 


Note: spatstat version 1.51-0 is out of date by more than 4 months; we recommend upgrading to the latest version.
Loading required package: spatial

Attaching package: 'spatial'

The following object is masked from 'package:spatstat':

    Strauss

spatstat documentation built on Jan. 10, 2019, 5:04 p.m.