[R-sig-Geo] Reading text files in Spatstat

Taylor, RB rbt501 at york.ac.uk
Wed Jul 4 11:55:23 CEST 2007


Just to finally finish off the thread, here is the code I used.

# read in the text data into a dataframe. "Rtest" is just x,y coords
 > test <- read.table("C:/temp/Rtest.txt")

# convert the data frame to a numeric matrix
 > test.matrix <- data.matrix(test)

# coerce the data into a ppp object in Spatstat
 > as.ppp(test.matrix,c(0,10,0,10),fatal=TRUE)
planar point pattern: 8 points
window: rectangle = [0, 10] x [0, 10] units

Taylor, RB wrote:
> ah, thank you Thierry. As a fairly new R user, this is most helpful :)
> 
> Cheers,
> Rob
> 
> ONKELINX, Thierry wrote:
>> I've found your problem. Test must be a matrix and you probably have a
>> data.frame.
>> I hope you see the importance of a reproducibel example of your code.
>> You MUST define the data too.
>>
>>
>> This works.
>>
>>> test <- matrix(runif(20, 0, 10), ncol = 2)
>>> as.ppp(test,c(0,10,0,10),fatal=TRUE)
>>  planar point pattern: 10 points 
>> window: rectangle = [0, 10] x [0, 10] units 
>>
>> This doesn't work.
>>
>>> test <- data.frame(test)
>>> as.ppp(test,c(0,10,0,10),fatal=TRUE)
>> Error in as.ppp.default(test, c(0, 10, 0, 10), fatal = TRUE) : 
>>         Can't interpret X as a point pattern
>>
>>
>> Cheers,
>>
>> Thierry
>>
>> ------------------------------------------------------------------------
>> ----
>> ir. Thierry Onkelinx
>> Instituut voor natuur- en bosonderzoek / Research Institute for Nature
>> and Forest
>> Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
>> methodology and quality assurance
>> Gaverstraat 4
>> 9500 Geraardsbergen
>> Belgium
>> tel. + 32 54/436 185
>> Thierry.Onkelinx at inbo.be
>> www.inbo.be 
>>
>> Do not put your faith in what statistics say until you have carefully
>> considered what they do not say.  ~William W. Watt
>> A statistical analysis, properly conducted, is a delicate dissection of
>> uncertainties, a surgery of suppositions. ~M.J.Moroney
>>
>>  
>>
>>> -----Oorspronkelijk bericht-----
>>> Van: Taylor, RB [mailto:rbt501 at york.ac.uk] 
>>> Verzonden: dinsdag 3 juli 2007 17:32
>>> Aan: ONKELINX, Thierry
>>> CC: r-sig-geo at stat.math.ethz.ch
>>> Onderwerp: Re: [R-sig-Geo] Reading text files in Spatstat
>>>
>>> Ok, "test" is just a small test data set of x, y coords.
>>>
>>> 3.45	5.34
>>> 2.78	5.67
>>> 3.89	1.345
>>> 2.34	3.78
>>> 3.45	5.34
>>> 2.78	5.67
>>> 3.89	1.345
>>> 2.34	3.78
>>>
>>>
>>> You could make it easily in Excel or a similar program. x 
>>> coords are in the first column, y coords are in the 2nd 
>>> column. It is saved as a tab delimited text file called "test".
>>>
>>>
>>> Cheers,
>>> Rob
>>>
>>> ONKELINX, Thierry wrote:
>>>> The problem is probably in "test". Try to give us a (small) 
>>> sample of 
>>>> test so we can reproduce your problem. Otherwise it will be hard to 
>>>> discover the problem.
>>>>
>>>> Thierry
>>>>
>>>>
>>> ----------------------------------------------------------------------
>>>> --
>>>> ----
>>>> ir. Thierry Onkelinx
>>>> Instituut voor natuur- en bosonderzoek / Research Institute 
>>> for Nature 
>>>> and Forest Cel biometrie, methodologie en kwaliteitszorg / Section 
>>>> biometrics, methodology and quality assurance Gaverstraat 4 9500 
>>>> Geraardsbergen Belgium tel. + 32 54/436 185 
>>> Thierry.Onkelinx at inbo.be 
>>>> www.inbo.be
>>>>
>>>> Do not put your faith in what statistics say until you have 
>>> carefully 
>>>> considered what they do not say.  ~William W. Watt A statistical 
>>>> analysis, properly conducted, is a delicate dissection of 
>>>> uncertainties, a surgery of suppositions. ~M.J.Moroney
>>>>
>>>>  
>>>>
>>>>> -----Oorspronkelijk bericht-----
>>>>> Van: r-sig-geo-bounces at stat.math.ethz.ch
>>>>> [mailto:r-sig-geo-bounces at stat.math.ethz.ch] Namens Taylor, RB
>>>>> Verzonden: dinsdag 3 juli 2007 17:11
>>>>> Aan: r-sig-geo at stat.math.ethz.ch
>>>>> Onderwerp: Re: [R-sig-Geo] Reading text files in Spatstat
>>>>>
>>>>> Right, I have supplied the W argument now. Still no joy though....
>>>>>
>>>>>  > as.ppp(test,c(0,10,0,10),fatal=TRUE)
>>>>> Error in as.ppp.default(test, c(0, 10, 0, 10), fatal = TRUE) :
>>>>>          Can't interpret X as a point pattern
>>>>>
>>>>> Any ideas anyone?
>>>>>
>>>>> Rob
>>>>>
>>>>> Don MacQueen wrote:
>>>>>> The help page for as.ppp() explains that in a case like
>>>>> yours (or what
>>>>>> I assume is yours from your description), you also need to
>>>>> supply the
>>>>>> W argument.
>>>>>>
>>>>>> Try looking at the help page for the ppp() function.
>>>>>>
>>>>>> -Don
>>>>>>
>>>>>> At 1:13 PM +0100 7/3/07, Taylor, RB wrote:
>>>>>>> Hello all,
>>>>>>>
>>>>>>> I have x,y data with an associated mark. Is there a 
>>> simple way of 
>>>>>>> getting Spatstat to read this data? I have tried putting 
>>> the x, y 
>>>>>>> data in separate columns in Excel and ignoring the marks,
>>>>> saving it
>>>>>>> as a tab-delim text file (called "test"). However the
>>>>> as.ppp function
>>>>>>> fails to convert it into a ppp object.
>>>>>>>
>>>>>>>
>>>>>>>  > test <- read.table("C:/temp/Rtest.txt")  > as.ppp(test)
>>>>> Error in
>>>>>>> as.ppp.default(test) : Can't interpret X as a point pattern
>>>>>>>
>>>>>>>
>>>>>>> Perhaps someone can answer my simple question and tell me
>>>>> what I am
>>>>>>> doing wrong?
>>>>>>>
>>>>>>> Thanks,
>>>>>>> Rob
>>>>>>> --
>>>>>>>
>>>>>>> _______________________________________________
>>>>>>> R-sig-Geo mailing list
>>>>>>> R-sig-Geo at stat.math.ethz.ch
>>>>>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>>> --
>>>>> Rob Taylor
>>>>>
>>>>> University of York
>>>>> Biology Department
>>>>> PO Box 373
>>>>> York
>>>>> YO10 5YW
>>>>> United Kingdom
>>>>>
>>>>> Work +44 (0)1904 32 8557
>>>>> Mob  +44 (0)777 258 5390
>>>>>
>>>>> _______________________________________________
>>>>> R-sig-Geo mailing list
>>>>> R-sig-Geo at stat.math.ethz.ch
>>>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>>>
>>> --
>>> Rob Taylor
>>>
>>> University of York
>>> Biology Department
>>> PO Box 373
>>> York
>>> YO10 5YW
>>> United Kingdom
>>>
>>> Work +44 (0)1904 32 8557
>>> Mob  +44 (0)777 258 5390
>>>
> 

-- 
Rob Taylor

University of York
Biology Department
PO Box 373
York
YO10 5YW
United Kingdom

Work +44 (0)1904 32 8557
Mob  +44 (0)777 258 5390




More information about the R-sig-Geo mailing list