我正在R中对我的数据(称为Ade)运行MCP(家庭范围)分析,这是一组动物位置的GPS点。
我运行了以下脚本:
Ade <- read.csv("Ade.csv")
#Get the folder SP that is used to convert the data
library(sp)
#Convert
Ade <- matrix(runif(1564), ncol=2)
head (Ade)
Ade <- data.frame(Ade)
#Convert Ade to spatial points data frame by first ...
#Tell R that the coordinates are in the column X and column Y
coords <- SpatialPoints(Ade[, c("X", "Y")])
AdeSpat <- SpatialPointsDataFrame(coords, Ade)
#Specify the coordinate reference system of the data
proj4string(AdeSpat) <- CRS("+proj=XY +ellps=WGS84")
#View data
getClass(AdeSpat)
class(AdeSpat)
head (AdeSpat)
#Two steps in loading AdehabitatHR into R
install.packages("adehabitatHR")
library(adehabitatHR)
#Run MCP
mcp <- mcp(AdeSpat$coordinates, percent=95, unin = c ("km"), unout = c("km2"))
但是当我运行时,我收到以下错误消息:
Error in mcp(AdeSpat$coordinates, percent = 95, unin = c("km"), unout =
c("km2")) : xy should be of class SpatialPoints
有人可以向我解释这意味着什么,以及我如何解决这个问题,我已经在互联网上搜索但找不到任何答案,因为错误“xy应该属于SpatialPoints类”。
当我检查数据框时,我得到以下输出:
> class(AdeSpat)
[1] "SpatialPointsDataFrame"
attr(,"package")
[1] "sp"
> head (AdeSpat)
coordinates ID ZONE X Y
1 (370984, 9752290) 1 36 M 370984 9752293
2 (370980, 9752290) 2 36 M 370980 9752288
3 (370980, 9752290) 3 36 M 370980 9752288
4 (370995, 9752290) 4 36 M 370995 9752287
5 (370995, 9752290) 5 36 M 370995 9752287
6 (371032, 9752310) 6 36 M 371032 9752312
Coordinate Reference System (CRS) arguments: +proj=XY +ellps=WGS84
谢谢J
答案 0 :(得分:0)
您必须直接放置包含空间点数据的对象。
在您的情况下,您的公式将是:
mcp&lt; - mcp(coords,percent = 95,unin = c(&#34; km&#34;),unout = c(&#34; km2&#34;))
我希望它会对你有所帮助!
Murielle