I struggled with this for some time and couldn't find a way to do this, so I would be incredibly grateful if you could help! I am new to programming and my code is probably inefficient, but that was the best I could come up with.
Basically, I have 2 CSV files (fixes.csv and .csv zones) that contain different variables and have different numbers of rows and columns. The first fixes.csv file contains eye movement data recorded during the experiment and looks something like this:
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
It contains eye movement records made while reading a sentence. It happens that each of the 20 participants reads a set of 40 sentences of 12 words, making several fixations on different words in each sentence and sometimes returning to previously read words. The StartPosition column contains the position on the screen (in degrees of the visual angle) where the fixation started. Values are usually between -8deg and 8deg.
The second zone.csv file contains offer information. Each of the 40 sentences contains 12 words, and each word forms one zone of interest. zone.csv looks something like this:
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
ZoneStart and ZoneEnd indicate the start and end coordinates of each zone on the screen (in degrees of visual angle). Since the words in each sentence are different, each zone has a width.
, , - , zone.csv fixations.csv. , Sentence 1 1, 1, :
Order Participant Sentence Fixation StartPosition Zone
1 1 1 1 -6.89 2
2 1 1 2 -5.88 2
3 1 1 3 -5.33 3
4 1 1 4 -4.09 3
5 1 1 5 -5.36 3
, , - .
zones = read.csv(file.choose(), header = TRUE, sep = ",")
fixes = read.csv(file.choose(), header = TRUE, sep = ",")
fixes$SentNo = as.factor(fixes$SentNo)
zones$Sentence = as.factor(zones$Sentence)
zones$Zone = as.factor(zones$Zone)
nfix = nrow(fixes)
nsent = nlevels(fixes$Sentence)
nzs = nlevels(zones1$Zone)
nsz = nlevels(zones$Sentence)
fixes$Zone = 0
for (i in c(1:nfix)){
for (j in c(1:nzs)){
for (k in c(1:nsent){
for (l in c(1:nsz)){
while(fixes$Sentence[k] == zones$Sentence[l]){
ifelse(fixes$StartPosition[i] > zones$ZoneStart[j]
& fixes$StratPosition[i] < zones1$ZoneEnd[j],
fixes$Zone[i] -> zones1$Zone[j], 0)
return(fixes$Zone)
}
}
}
}
, . .csv , ? Sentence , , , .
!
!