Q:

R Data. Table Indexing Previous Cell Value

I'm trying to create a variable (below) within a data table: 
Prob_RF_RR:   probability that subject chose rich on a rich trial following a rich feedback trial §
In the context of the script/data; "long" = rich, z = response to rich stimuli 
Sample of the data:

For the variable I need to index the previous [condition] cell to see if it contains the condition equal to “long”.  I believe the line should be something like this:
Prob_RF_RR=.SD[previous"long"=="long" & condition=="long" & response==z ... ]

How do I reference the previous cell in this context?  

A:

Assuming your data ( .SD ?)  is in order of trial number, you can use zoo to turn the dataset into a time series object and create a lagged variable for condition.   For example:
library(zoo)
.SD <- zoo( .SD )
.SD$PreviousCondition <- c(NA , lag( .SD$condition ) )
.SD <- as.data.frame( .SD )
Prob_RF_RR <- .SD[condition == PreviousCondition & condition=="long" & response==z ... ]

