dmirman-zz / gazer

Functions for reading and pre-processing eye tracking data.
16 stars 14 forks source link

Merging Samples and Messages #15

Closed jgeller112 closed 4 years ago

jgeller112 commented 4 years ago

@tjmahr

As I mentioned there are some issues with merging the sample and message data.

I am not going to make you download the SR API. I am attaching two ds, one with the samples and one with messages I am trying to merge. A lot of this is contained in the parse_edf function.


library(data.table)
remotes::install.github("dmirman/gazer")
library((gazer)

 # I put the files on the git(not best practice) but will remove them after
samp <- system.file("extdata", "TJ_samp.xls", package = "gazer")
samp <- data.table::fread(samp, stringsAsFactors = FALSE) # reads in large datasets 

msg <- system.file("extdata", "TJ_msg.xls", package = "gazer")
msg <- data.table::fread(msg, stringsAsFactors = FALSE) # reads in large datasets 
setDT(samp)
setDT(msg)

DT_mesg <- msg[samp, on="time", roll="nearest"] # use this to get close to values in sample report

DT_mesg
 #SR edfs are a nightmare. This makes it so messages are alined with closest values 
get_msg <- DT_mesg %>% 
  group_by(trial, message) %>% 
  top_n(n=1, wt=desc(time)) # there are a lot of useless messages and they occupy the same time stamp. Only take the first message in time. 

get_msg

dat_samp_msg <- dplyr::full_join(blinks, get_msg, by=c("time", "trial","x", "y", "Label", "pup"))

dat_samp_msg
jgeller112 commented 4 years ago

I was able to figure it out...

setDT(samp)
setDT(msg)

DT_mesg <- msg[samp, on="time", roll=4] gives me my desired result, or close to it.