Error in data frame

44 views
Skip to first unread message

Tamara Potter

unread,
Aug 31, 2020, 9:22:51 AM8/31/20
to camtrapR
Hi Jürgen,

I'm trying to use an existing spreadsheet and am having issues with the  'assessTemporalIndependence' function. Specifically, I am getting the error:

Error in Ops.data.frame(intable[, cameraCol], intable[xy, cameraCol]) : 
  ‘==’ only defined for equally-sized data frames

This is my code:

records <- read.csv("record_table_Simpson_Desert.csv",
                    stringsAsFactors = FALSE)
records$DateTimeOriginal <- strptime(paste(records$Date, records$Time, sep = " "), format = "%d-%b-%y %H:%M")

# create DateTimeOrginal column in proper format
records$DateTimeOriginal <- strptime(paste(as.Date(records$Date, format = "%y/%m/%d"),
                                           records$Time), format = "%Y-%m-%d %H:%M:%S", tz = "Australia/Sydney")
str(records)
# assign a species
records$FaunaSpecies <- "Lycosid"

records_filter15_min <- camtrapR:::assessTemporalIndependence(intable = records,
                                                  deltaTimeComparedTo = "lastIndependentRecord",
                                                  columnOfInterest = "FaunaSpecies",
                                                  stationCol = "Station",
                                                  camerasIndependent = TRUE,
                                                  minDeltaTime = 15)

Where am I going wrong?
Data is attached.

Thanks in advance!
record_table_Simpson_Desert.csv

Juergen Niedballa

unread,
Sep 8, 2020, 6:33:10 AM9/8/20
to camtrapR
Hi Tamara, 
sorry for the late reply. 
There's a few issues:

1) DateTimeOriginal is not correct:
range(records$DateTimeOriginal)
"2001-08-20 00:05:00 AEST" "2031-08-20 23:25:00 AEST"

Try this, it's easier with lubridate:

library(lubridate)
records$DateTimeOriginal <- parse_date_time(paste(records$Date, records$Time, sep = " "), orders = "dmy HMS")   # UTC time zone

2) there is no camera column, so set  camerasIndependent = FALSE

After adjusting these it works:

> str(records_filter15_min)
'data.frame': 1499 obs. of  14 variables:
 $ Station         : chr  "CAM01" "CAM01" "CAM01" "CAM01" ...
 $ FaunaSpecies    : chr  "Lycosid" "Lycosid" "Lycosid" "Lycosid" ...
 $ Date            : chr  "8/07/2016" "11/07/2016" "11/07/2016" "18/07/2016" ...
 $ Time            : chr  "6:40:00" "19:30:00" "20:55:00" "22:20:00" ...
 $ Habitat         : chr  "burnt" "burnt" "burnt" "burnt" ...
 $ Location        : chr  "crest" "crest" "crest" "crest" ...
 $ Position        : chr  "angle" "angle" "angle" "angle" ...
 $ FileName        : chr  "MC01_IMG_9855.JPG" "MC01_IMG_9413.JPG" "MC01_IMG_9396.JPG" "MC01_IMG_8355.JPG" ...
 $ DateTimeOriginal: POSIXct, format: "2016-07-08 06:40:00" "2016-07-11 19:30:00" "2016-07-11 20:55:00" "2016-07-18 22:20:00" ...
 $ delta.time.secs : num  0 305400 5100 609900 200100 ...
 $ delta.time.mins : num  0 5090 85 10165 3335 ...
 $ delta.time.hours: num  0 84.8 1.4 169.4 55.6 ...
 $ delta.time.days : num  0 3.5 0.1 7.1 2.3 4.7 9.9 5.4 12.8 8.8 ...
 $ n_images        : int  1 1 1 1 1 1 2 2 1 1 ...

And as I mentioned before, using camtrapR:::assessTemporalIndependence is just a workaround until I get to write a proper function that does the filtering and some checks too that the input data are correct. Currently, assessTemporalIndependence is just an internal function that does not check the input and does not give any useful error messages. 
If there's more issues, please let us know.
Best regards,
Jürgen
Reply all
Reply to author
Forward
0 new messages