2015-10-14 259 views
0

我在R中使用adehabitatHR,試圖計算家庭範圍重疊。我成功地爲兩個不同的動物(分別是個體70F和153F)加載了兩個.tsv文件和位置數據。 .tsv文件有5列,其中2列是緯度和經度數據(DDE和DDS);以十進制度數。然而,當我嘗試轉換爲座標,我得到以下錯誤:錯誤.local(obj,)cannat從非數字矩陣派生座標

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

這裏是我的腳本:

> 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 

我難倒。有人有主意嗎?

回答

0

你在這個地方分配兩個項目特徵向量的座標:

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

你需要指定它的實際列,例如使用一個公式:

coordinates(locs153M) <- ~DDE + DDS