Hi, On Tue, Jun 11, 2013 at 12:55 PM, Dylann Kersusan
<kersusan.dylann at gmail.com> wrote:
Thanks a lot. It works perfectly fine! Though I don't know how to arrange that into a column, I shall find something not too time consuming.
The code I provided extracts the distances as a vector. What are you trying to do with them? ltrj.obj[[1]]['dist'] will return a one-column data frame. You might like to take some time to read the intro to R documentation, particularly the parts about subsetting and the difference between [ and [[ to understand why. Sarah
2013/6/11 Sarah Goslee <sarah.goslee at gmail.com>
Hi Dylann, On Tue, Jun 11, 2013 at 11:36 AM, Dylann Kersusan <kersusan.dylann at gmail.com> wrote:
Hi everyone,
I am working on class object "ltraj" mainly using the package Adehabitat
HT
and LT.
Is there a way to extract from this class object the distances between
relocations ("dist")? I am pretty sure that it is possible and it has to
be
easy, but I am probably missing something. I tried the following though:
ltrj.obj <- as.ltraj(xy, date = dates, id = data$name, infolocs =
data.frame(idnr = data$idnr))
str(ltrj.obj)
List of 1
$ :'data.frame': 1328 obs. of 10 variables:
..$ x : int [1:1328] 1559670 1559665 1559687 1559695 1559695
1559686 1559687 1559674 1559648 1559666 ...
..$ y : int [1:1328] 7448557 7448603 7448611 7448592 7448594
7448598 7448599 7448568 7448522 7448532 ...
..$ date : POSIXct[1:1328], format: "2009-05-15 00:00:54"
"2009-05-15 00:30:21" "2009-05-15 01:00:35" ...
..$ dx : int [1:1328] -5 22 8 0 -9 1 -13 -26 18 2 ...
..$ dy : int [1:1328] 46 8 -19 2 4 1 -31 -46 10 -2 ...
..$ dist : num [1:1328] 46.27 23.41 20.62 2 9.85 ...
..$ dt : num [1:1328] 1767 1814 1842 1766 1799 ...
distance <- ltrj.obj$data.frame$dist
You're conflating class and name. A ltraj object is a list of data frames. Your list happens to only have one data frame, but there can be many. That data frame has 10 columns, and str() gives the names, as would names(ltrj.obj[[1]]) length(ltrj.obj) # should be 1, based on the output you showed ltrj.obj[[1]]$dist will give you what you're looking for, as would ltrj.obj[[1]][['dist']]
Sarah Goslee http://www.functionaldiversity.org