Using the following reaction time data (simplified for demonstrative purposes):
>dt
subject trialnum blockcode values.trialtype latency correct
1 1 1 practice cueswitch 3020 1
2 1 1 test cuerep 4284 1
3 1 21 test cueswitch 2094 1
4 1 34 test cuerep 3443 1
5 1 50 test taskswitch 3313 1
6 2 1 practice cueswitch 3020 1
7 2 1 test cuerep 1109 1
8 2 21 test cueswitch 3470 1
9 2 34 test cuerep 2753 1
10 2 50 test taskswitch 3321 1
I have been using data.table to obtain reaction time variables for consecutive subsets of trials (specified by trialnum, which ranges from 1 to 170 in the full dataset):
dt1=dt[blockcode=="test" & correct==1, list(
RT1=.SD[trialnum>=1 & trialnum<=30 & values.trialtype=="cuerep", mean(latency)],
RT2=.SD[trialnum>=31 & trialnum<=60 & values.trialtype=="cuerep", mean(latency)]
), by="subject"]
The output is
subject RT1 RT2
1: 1 4284 3443
2: 2 1109 2753
However, it becomes tedious creating a variable for each subset when there are more than 2 or 3 subsets. How can I specify those subsets more efficiently?