I have been struggling with this for some time now and couldn\'t find any way of doing it, so I would be incredibly grateful if you could help! I am a novice in programming
With version v1.9.8 (on CRAN 25 Nov 2016), data.table
has gained the ability to perform non-equi joins and range joins:
library(data.table)
setDT(fixes)[setDT(zones),
on = .(Sentence, StartPosition >= ZoneStart, StartPosition < ZoneEnd),
Zone := Zone][]
Order Participant Sentence Fixation StartPosition Zone 1: 1 1 1 1 -6.89 2 2: 2 1 1 2 -5.88 3 3: 3 1 1 3 -5.33 3 4: 4 1 1 4 -4.09 4 5: 5 1 1 5 -5.36 3
fixes <- readr::read_table(
"Order Participant Sentence Fixation StartPosition
1 1 1 1 -6.89
2 1 1 2 -5.88
3 1 1 3 -5.33
4 1 1 4 -4.09
5 1 1 5 -5.36"
)
zones <- readr::read_table(
"Sentence Zone ZoneStart ZoneEnd
1 1 -8.86 -7.49
1 2 -7.49 -5.89
1 3 -5.88 -4.51
1 4 -4.51 -2.90"
)