Skip to content
Prev 4343 / 29559 Next

Create/convert a point pattern from raw txt file in spatstat?

2008/10/14  <opheliawang at mail.utexas.edu>:
That's a clue there. Something in your data isn't a number. Now your
file looks like all numbers.. except... those headers!

 You need to tell read.table that you've got headings, by using
head=TRUE. Compare:

 > test = read.table("tree.txt")
 > test[1:5,]
     V1   V2   V3     <- R made these headings
 1    X    Y Mark     <- oops
 2    1   94    1
 3  2.5 94.5    4
 4    3   93    5
 5    4   92    6

 > test = read.table("tree.txt",head=TRUE)
 > test[1:5,]
      X    Y Mark    <- R's headings
 1  1.0 94.0    1  <-  your data starts here
 2  2.5 94.5    4
 3  3.0 93.0    5
 4  4.0 92.0    6
 5  4.0 95.0    7

from there, as.ppp(test,w) works fine:
marked planar point pattern: 14 points
marks are numeric, of type 'integer'
window: rectangle = [0, 100] x [0, 100] units
Warning message:
In ppp(X[, 1], X[, 2], window = win, check = check) :
  data contain duplicated points

 If you still get errors with head=TRUE then there's something else in
your data file that's not a number. Read some introductory R docs on
reading data (help(read.table) for starters).

 summary(test) and str(test) will tell you things about test before
you go on and try and do things with it. You should always make sure
step N is okay before assuming the problem is with step N+1...

Barry