.local(obj,)中的错误cannat从非数字矩阵派生坐标

时间:2015-10-14 15:36:36

标签: r gis adehabitathr

我在R中使用adehabitatHR,试图计算家庭范围重叠。我已经成功加载了两个.tsv文件,其中包含两种不同动物的位置数据(分别为70F和153F)。 .tsv文件有5列,其中2列是纬度和经度数据(DDE和DDS);十进制度。但是,当我尝试转换为坐标时,我收到以下错误:

  

坐标(locs153M)< - c(" DDE"," DDS")   .local(obj,...)出错:     无法从非数字矩阵

派生坐标

这是我的剧本:

> 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 

警告讯息:

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

我很难过。有人有什么想法吗?

1 个答案:

答案 0 :(得分:0)

您将两项角色向量分配给此位置的坐标:

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

您需要使用例如公式

为其分配实际列
coordinates(locs153M) <- ~DDE + DDS