F.assign.batch.date | R Documentation |
Assigns batch dates to all trap visits in a data frame via global
variable samplePeriodCutTime
.
F.assign.batch.date(df)
df |
The data frame containing trap visit records for which a day must be assigned. |
In order to process the sequence of dates correctly, function
F.assign.batch.date
first identifies the earliest and latest dates
in the provided data frame's trapping EndTime
variable. Given
EndTime
dates and times, it then moves back one day in time, and two
forward; this encapsulates the earliest and latest EndTime
dates.
Given the unique dates within this resulting range, each of which start at
12:00 midnight, it then adds the value of global variable
samplePeriodCutTime
, or 4:00 AM. The time of 4:00 AM was chosen so
as to not prematurely cut-off trapping instances that often continue past
midnight. This effectively moves the traditional day-separation time of
midnight to 4:00 AM.
Function F.assign.batch.date
maps trapping records containing
trapping-instance variable EndTime
s to particular days, taking into
consideration that trapping instances often take place over midnight, i.e.,
two separate calendar days. This function also considers multi-day
trapping instances. All calculations consider daylight savings time and
assume that measurements take place within the Pacific Time Zone.
Generally, the variable created by function F.assign.batch.date
,
batchDate
, is the same as variable SampleDate
found in
query-derived table TempSumUnmarkedByTrap_Run_Final
in any CAMP
Database. See section Structured Query Language (SQL) Queries in
F.run.sqlFile
. Variable batchDate
replaces variable
SampleDate
in all dataframes for which function
F.assign.batch.date
is called.
The same data frame df
submitted to the function, with new
variable batchDate
replacing old variable SampleDate
.
WEST Inc.
## Not run: # ---- Set the time zone to Pacific. time.zone <- "America/Los_Angeles" # ---- Create a data set of three trapping instances. origDate <- data.frame(trapVisitID=c(1234,1235), SampleDate <- strptime(c("2014-01-24","2014-01-24"),"%F"), StartTime <- strptime(c("2014-01-23 14:28:00","2014-01-24 03:59:00"), "%Y-%m-%d %H:%M:%S", tz=time.zone), EndTime <- strptime(c("2014-01-24 03:59:00","2014-01-24 04:00:00"), "%Y-%m-%d %H:%M:%S", tz=time.zone)) # ---- BatchDate for trapVisitID=1234 is now 1/23, # ---- since that trap stopped before 4 AM. newDate <- F.assign.batch.date(origDate) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.