0

I am trying to analyze spatial data in R. I ran into problems trying to subset my data for the analysis. First of all my raw data had this format. The Dataframe is called "locs":

  AnID      X          Y
1 Ind7   408046.3   5508986
2 Ind7   407445.4   5508927
3 Ind7   407588.2   5508927
4 Ind7   407595.9   5508819
5 Ind7   408079.9   5508904

It contains the coordinates for seven different animals (Ind1-Ind7). When i turned it into SpatialPointsDataFra‌​‌​‌me and used the head(locs) command I got this:

  AnID
1 Ind7
2 Ind7
3 Ind7
4 Ind7
5 Ind7
6 Ind7

So as you can see all the coordinates are gone. I try to subset the data so that only the rows of Ind3 are available.

Animal3 <- locs[as.data.frame(locs)[,1]=="Ind3",]

When i plot this data i can see all 75 locations perfectly but when i use the following command i get an error:

kernelUD(Animal3, h=293, grid=ab)

The error says:

Error in `kernelUD(Animal3, h = 293, grid = ab)` : 
  At least 5 relocations are required to fit an home range
h4g0
  • 1
  • 3
  • please provide the actual data you're using. You mentioned you have a data frame but from the sounds of it, you don't. what does ``class(loc)`` spit out at you? – Cyrus Mohammadian Aug 16 '16 at 03:59
  • After i turned my raw data into SpatialPointsDataFrame. Class() gives out 1] "SpatialPointsDataFrame"attr(,"package")[1] "sp" for both. – h4g0 Aug 16 '16 at 09:00
  • SpatialPointsDataFra‌me? or Spatialpixeldataframe???? – Cyrus Mohammadian Aug 16 '16 at 09:04
  • also it would help to provide actual data and full workflow.... – Cyrus Mohammadian Aug 16 '16 at 09:05
  • `> locs <- read.csv2("C:/Users/xxxDesktop/rcsv/locs.csv") > View(locs) > coordinates(locs) <- c("X", "Y") > proj4string(locs) <- CRS("+init=epsg:3044") > class(locs) [1] "SpatialPointsDataFrame" attr(,"package") [1] "sp" > Animal3 <- locs[as.data.frame(locs)[,1]=="Ind3",] > Animal3 coordinates AnID 274 (408562.2, 5509339) Ind3 275 (408535.4, 5509348) Ind3 276 (408532.7, 5509341) Ind3 277 (408518.6, 5509318) Ind3 278 (408518.4, 5509356) Ind3 279 (408518.6, 5509394) Ind3 280 (408549, 5509418) Ind3 281 (408573.8, 5509391) Ind3` – h4g0 Aug 16 '16 at 09:20
  • > class(Animal3) [1] "SpatialPointsDataFrame" attr(,"package") [1] "sp" `> kernelUD(Animal3, h = 293, grid = 60) Error in kernelUD(Animal3, h = 293, grid = 60) : At least 5 relocations are required to fit an home range` The raw data is totally like show in my first post with 403 rows and 3 columns. The problem must come from the subsetting. I guess – h4g0 Aug 16 '16 at 09:21
  • 1
    please post reproducible data if you want help on stack overflow. we don't have access to your local hard drive!! also you said SpatialPointsDataFra‌me in your comment but on the post you said Spatialpixeldatafram‌e – Cyrus Mohammadian Aug 16 '16 at 09:22
  • It is SpatialPointsDataFra‌​‌me. I made a mistake in my first post. How do I attach my data? Comments only allow limited characters? – h4g0 Aug 16 '16 at 09:26
  • 1
    re edit your original post, but thats besides the point. ``locs <- read.csv2("C:/Users/‌​xxxDesktop/rcsv/locs.‌​csv") `` is meaningless to us, we don't have access to your hard. either recreate the data in line, produce similar data as an example, or post a link to the data. – Cyrus Mohammadian Aug 16 '16 at 09:28
  • and why mention Indy 1-7 when your example has only Indy1? also its impossible that ``head(lots)`` produced what you say it produced ``head()`` only spits out the first 5 rows... – Cyrus Mohammadian Aug 16 '16 at 09:31
  • Also X and Y don't look like coordinates to me... – Cyrus Mohammadian Aug 16 '16 at 09:36
  • Please use `dput(locs)` to and add the result to your question. Otherwise, we can't reproduce the issue. – epo3 Aug 16 '16 at 09:39
  • they are utm. when i load in dataframes containing only one animal at a time it works. so i guess it can only be me subsetting the data wrong. i'll try to work around – h4g0 Aug 16 '16 at 09:40

0 Answers0