Hi Patrick & Samantha,
here's the function that does the job inside recordTable(). You can use it on your existing record tables.
By popular demand, I'll add it as a standalone function in the next release with proper help file and all.
For now it is just a quick fix and lacks some flexibility because it is normally called from within the recordTable function. Hence, it does not perform checks to ensure data consistency. It also does not return the data exactly like recordTable does because some of the computation is happening outside the attached function.
Input:
- argument "cameraCol" is optional
- "minDeltaTime" is in minutes.
- "removeNonIndependentRecords" is TRUE by default and will remove all non-independent records from output. Set to FALSE to return all records.
output:
- input table minus the non-independent records
- additional "delta.time..." columns, but only "delta.time.secs" has data, the rest is NA still (divide by 60 / 60*60 / 60 * 60 * 24 to compute mins / hours / days)
- additional column "independent". records within "minDeltaTime" will be FALSE. Can be used to remove non-independent records
Also note I had to change your data slightly to run it (see below):
- assign values to "Species"
- format column "DateTimeOriginal"
So, source the function in the attached file, then you can run something like the following code to filter your records:
If you run into problems, let me know please.
Jürgen
records <- read.csv("C:/.../camtrapR_example.csv",
stringsAsFactors = FALSE)
# create DateTimeOrginal column in proper format
records$DateTimeOriginal <- strptime(paste(as.Date(records$Date, format = "%m/%d/%y"),
records$Time), format = "%Y-%m-%d %H:%M:%S", tz = "UTC")
# assign a species
records$Species <- "lion"
#
records_filter1_min <- assessTemporalIndependence(intable = records,
deltaTimeComparedTo = "lastIndependentRecord",
columnOfInterest = "Species",
cameraCol = "Camera.Serial.Number",
camerasIndependent = FALSE,
minDeltaTime = 1
)
records_filter30_min <- assessTemporalIndependence(intable = records,
deltaTimeComparedTo = "lastIndependentRecord",
columnOfInterest = "Species",
cameraCol = "Camera.Serial.Number",
camerasIndependent = FALSE,
minDeltaTime = 30
)
View(records)
View(records_filter1_min)
View(records_filter30_min)
# assign 2 different species
records$Species <- c(rep("lion", times = 3),
rep("giraffe", times = nrow(records) - 3))
records_filter30_min_2_spec <- assessTemporalIndependence(intable = records,
deltaTimeComparedTo = "lastIndependentRecord",
columnOfInterest = "Species",
cameraCol = "Camera.Serial.Number",
camerasIndependent = FALSE,
minDeltaTime = 30
)
View(records_filter30_min_2_spec)
# remove argument cameraCol, and set removeNonIndependentRecords = FALSE
records_filter30_min_2_spec_return_all <- assessTemporalIndependence(intable = records,
deltaTimeComparedTo = "lastIndependentRecord",
columnOfInterest = "Species",
# cameraCol = "Camera.Serial.Number",
camerasIndependent = FALSE,
minDeltaTime = 30,
removeNonIndependentRecords = FALSE
)
View(records_filter30_min_2_spec_return_all)