1

I am using adehabitatHR in R, trying to calculate home range overlap. I have successfully loaded two .tsv files with location data for two different animals (individuals 70F and 153F respectively). The .tsv files have 5 columns, 2 of which are the latitude and longitude data (DDE and DDS); in decimal degrees. However, when I try to convert to coordinates I get the following error:

coordinates (locs153M) < - c ("DDE", "DDS") Error in .local(obj, ...) : cannot derive coordinates from non-numeric matrix

Here is my script:

> locs07F <- read.delim("C:\\Users\\cpickering\\Documents\\Black Rhino\\Management Plan 2015\\Maps\\Sightings_07F.tsv", header = TRUE)
> library(adehabitatHR)
Loading required package: sp
Loading required package: deldir
deldir 0.1-9
Loading required package: ade4
Loading required package: adehabitatMA
Loading required package: adehabitatLT
Loading required package: CircStats
Loading required package: MASS
Loading required package: boot
> library (maptools)
Checking rgeos availability: TRUE
> library(rgeoos)
Error in library(rgeoos) : there is no package called ‘rgeoos’
> library (rgeos)
rgeos version: 0.3-13, (SVN revision 508)
 GEOS runtime version: 3.4.2-CAPI-1.8.2 r3921 
 Linking to sp version: 1.2-0 
 Polygon checking: TRUE 

Warning message:

package ‘rgeos’ was built under R version 3.2.2 
> class (locs07F)
[1] "data.frame"
> coordinates (locs07F) < - c ("DDE", "DDS")
Error in .local(obj, ...) : 
  cannot derive coordinates from non-numeric matrix
> locs153M <- read.delim("C:\\Users\\cpickering\\Documents\\Black Rhino\\Management Plan 2015\\Maps\\Sightings_153M.tsv", header = TRUE)
> class (locs153M)
[1] "data.frame"
> coordinates (locs153M) < - c ("DDE", "DDS")
Error in .local(obj, ...) : 
  cannot derive coordinates from non-numeric matrix
> locs153M(,)
Error: could not find function "locs153M"
> head("locs153M", n = 10)
[1] "locs153M"
> head(locs153M)
  SightingID       Date       DDS      DDE     RhinosAtSighting
1       2489 24/08/2015 -27.85235 32.29086 161, 07, 07-C-2014, 
2       2472 15/08/2015 -27.84257 32.30194           160, 161, 
3       2447 09/07/2015 -27.85831 32.29140                161, 
4       2438 01/07/2015 -27.83754 32.31780           154, 160, 
5       2424 06/06/2015 -27.84686 32.35096           154, 160, 
6       2403 20/05/2015 -27.83959 32.30993                161, 
> summary(locs153M)
   SightingID           Date         DDS              DDE         RhinosAtSighting
 Min.   :1032   15/04/2014: 2   Min.   :-27.87   Min.   :32.28   07,      :25     
 1st Qu.:1378   01/07/2013: 1   1st Qu.:-27.85   1st Qu.:32.30   154,     :14     
 Median :1645   01/07/2015: 1   Median :-27.85   Median :32.31   07, 161, : 7     
 Mean   :1743   01/09/2011: 1   Mean   :-27.85   Mean   :32.32   161,     : 6     
 3rd Qu.:2153   02/02/2012: 1   3rd Qu.:-27.84   3rd Qu.:32.32   160,     : 5     
 Max.   :2489   02/04/2014: 1   Max.   :-27.83   Max.   :32.35            : 4     
                (Other)   :76                                    (Other)  :22     
> library (rgdal)
rgdal: version: 1.0-7, (SVN revision 559)
 Geospatial Data Abstraction Library extensions to R successfully loaded
 Loaded GDAL runtime: GDAL 1.11.2, released 2015/02/10
 Path to GDAL shared files: C:/Program Files/R/R-3.2.1/library/rgdal/gdal
 GDAL does not use iconv for recoding strings.
 Loaded PROJ.4 runtime: Rel. 4.9.1, 04 March 2015, [PJ_VERSION: 491]
 Path to PROJ.4 shared files: C:/Program Files/R/R-3.2.1/library/rgdal/proj
 Linking to sp version: 1.2-0 
> coordinates (locs153M) < - c ("DDE", "DDS")
Error in .local(obj, ...) : 
  cannot derive coordinates from non-numeric matrix

I'm stumped. Anyone have any ideas?

MikeCAT
  • 73,922
  • 11
  • 45
  • 70
CillaP
  • 11
  • 1
  • 4

1 Answers1

0

You're assigning a two-item character vector to the coordinates in this spot:

coordinates(locs153M) <- c("DDE", "DDS")

You need to assign it the actual columns, using eg a formula:

coordinates(locs153M) <- ~DDE + DDS
Jesse Anderson
  • 4,507
  • 26
  • 36