A possible solution very much inspired by @thelatemail's and @Justin's previous, nice answers, but this accounts for time in the boolean expression for space (see my comments to this question).
Using sapply
, we 'loop' over each time of registration of Species A (time[SP == "A"]
), and create a boolean matrix mm
with one column per registration of A. Each row represents a test for space and time for each registration against a given registration of A.
mm <- with(dat,
sapply(time[SP == "A"], function(x)
abs(AR - AR[SP == "A" & time == x]) <= 1 &
abs(difftime(time, x, units = "mins")) <= 30))
# select rows from data where at least one column in mm is TRUE
dat[rowSums(mm) > 0, ]
# SP time AR
# 3 A 2003-01-01 09:22:00 1
# 5 D 2003-01-01 09:20:00 1
# 7 D 2003-01-01 09:03:00 1
# 8 E 2003-01-01 09:12:00 2
# 9 F 2003-01-01 09:45:00 1
# 11 A 2003-01-03 10:30:00 5
# 13 F 2003-01-03 10:20:00 6
# 14 D 2003-01-03 10:05:00 4