time <- as.POSIXct('2020-01-01 12:00:00', tz='UTC')
data <- data.frame(UTC=time+c(0, 30, 60, 90, 120),
end=time+c(30, 60, 90, 120, 150))
detection <- data.frame(UTC=time+c(25, 90),
end=time+c(40, 95),
species=c('A', 'B'))
# Create a new "presence" column and fill with TRUE
matchDetectionData(data, detection, name='presence', value=TRUE)
# Fill non-matching times with FALSE (instead of default NA)
matchDetectionData(data, detection, name='presence', value=TRUE, fillNA=FALSE)
# Instead fill with value from "species" column
matchDetectionData(data, detection, name='presence', value='species')
detection <- data.frame(UTC=time+c(25, 90, 18, 30),
end=time+c(40, 95, 28, 40),
site=c('east', 'east', 'west', 'west'),
species=c('A', 'B', 'A', 'B'))
data <- data.frame(UTC=time+c(0, 30, 60, 90, 120, 0, 30),
end=time+c(30, 60, 90, 120, 150, 30, 60),
deployment=c(rep('east', 5), rep('west', 2)))
# detection now has overlapping times, so this will trigger a warning
matchDetectionData(data, detection, name='presence', value='species')
# mode='add' will change this to concatenate the labels for overlaps
matchDetectionData(data, detection, name='presence', value='species', mode='add')
# but really these correspond to different locations, so we can use "by" for that
matchDetectionData(data, detection, name='presence', value='species', by=c('deployment'='site'))
# this is another way to specify "by"
matchDetectionData(data, detection, name='presence', value='species', by='deployment'=='site')
Run the code above in your browser using DataLab