[R] Class ltraj and function as.ltraj

Michael Sumner
2014-10-02T21:47:36Z

You don't detail how you detect that 'there are no duplicates', and
also provide no proof of this. It's not the usual sense of
duplicated(), it needs to be that there are no date-times within a
burst (a single animal's trip/journey/trajectory). Can you try this on
your datetime and burst id and report:

## this tests out ok
datetime <- seq(Sys.time(), by = "3 secs", length = 20)
id <- rep(c("a", "b"), each = 10)

## none should be zero or negative
sapply(split(datetime, id), function(x) min(diff(x)))

## fudge a broken data set
datetime1 <- datetime
datetime1[15] <- datetime1[14]
sapply(split(datetime1, id), function(x) min(diff(x)))

Cheers, Mike.


On Fri, Oct 3, 2014 at 4:30 AM, tandi perkins <idnat at hotmail.com>
wrote:
> Hello R Help Group:
>
> I have been struggling to create
> an object of class ltraj with the function as.ltraj (adehabitatLT) with my
bird
> data.  Regarding my data structure, I
> have GPS for 10 birds that transmit three times/day, over the course of a
year
> (with missing data).  I have a L10.csv
> file with the following headers: Craneid, Date, Time, Long, Lat, Habitat,
ID
> (for burst).
>
>
>
> Step 1:  Bring in my data with: ?stringsasFactors=FALSE? to convert all
variables from Factor (except Lat/Long) to strings.  Thanks to David Carlson for
that tip! Step 2: Transform my date, time vectors into POSIXct as follows:
datetime=as.POSIXct(strptime(paste(L10$Date, L10$Time, sep="
"),format="%m/%d/%Y %H:%M:%S", "America/Chicago"))
Thanks to Petr Pikal for that tip! Result: head(datetime)[1] "2011-07-10
17:00:38 CDT" "2011-07-11 00:01:06 CDT"[3] "2011-07-11
08:00:38 CDT" "2011-07-11 17:00:38 CDT"[5] "2011-07-12
00:01:06 CDT" "2011-07-12 08:00:38 CDT"   Good so far?. Step 3:
Coord=L10[c("Longitude", "Latitude")]> head(Coord)
Longitude Latitude1    522598  33602852    522579  33601743    522618  33602744
522656  33601965    522397  33602076    522425  3360285 Good so far?.now comes
the tricky part for me. Step 4: Craneid=as.character(L10$Craneid)
id=as.character(L10$ID)
>
>
>
> Step 5: Test=as.ltraj(Coord, datetime, Craneid, burst=id,
> type=TRUE)
>
>
>
> Drum Roll Please?. Error in
> as.ltraj(Coord, datetime, Craneid, burst = id, typeII = TRUE) :
>
>
> non unique dates for a given burst
>
> I include my data.frame for your
> review.
>
>
>
> head(l10b)
>
>
> Longitude Latitude
> datetime               Craneid    id
>
> 1    522598
> 3360285 2011-07-10 17:00:38
> L1_10 L1_10
>
> 2    522579
> 3360174 2011-07-11 00:01:06
> L1_10 L1_10
>
> 3    522618
> 3360274 2011-07-11 08:00:38
> L1_10 L1_10
>
> 4    522656
> 3360196 2011-07-11 17:00:38
> L1_10 L1_10
>
> 5    522397
> 3360207 2011-07-12 00:01:06
> L1_10 L1_10
>
> 6    522425
> 3360285 2011-07-12 08:00:38
> L1_10 L1_10
>
>
>
>
> Longitude Latitude
> datetime                     Craneid    id
>
> 3803    558205
> 3346410 2011-04-15 17:00:38
> L5_10 L5_10
>
> 3804    552813
> 3341251 2011-04-16 08:00:38
> L5_10 L5_10
>
> 3805    552784
> 3341373 2011-04-28 08:00:38
> L5_10 L5_10
>
> 3806    552833
> 3341262 2011-04-28 17:00:38
> L5_10 L5_10
>
> 3807    573502
> 3407390 2011-06-21 17:00:38
> L8_10 L8_10
>
> 3808    573271
> 3407499 2011-06-23 08:00:38
> L8_10 L8_10
>
>
>
> I have checked and re-checked for
> duplicates and there are no duplicates.  However,
> when ask for duplicates in the datetime I get some ?False? but a lot of
?True?s?
> So, I am thinking it has to do with the fact that R is not picking up the
> individual birds which were monitored over the same time period.
>
>
>
> How do I structure my data in R to recognize the 10 separate birds with
their associated coordinates and time
> stamps?
>
>
>
> I would ultimately like to run
> Bias Bridge Movement on these data but I can?t get from square one!  Help!
>
>
>
> Thanks in advance for any and all
> assistance you can provide?You all are so valuable.
> TLP
>
>
>
>         [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



--
Michael Sumner
Software and Database Engineer
Australian Antarctic Division
Hobart, Australia
e-mail: mdsumner at gmail.com