Asuuming that you want to calculate all the possible lags with sapply/lapply in r
IPC=data.frame(Close=seq(100,120))
# both nested double sapply and outer worked identically in this case
t1 <-sapply(1:length(IPC$Close), function(x) sapply(1:length(IPC$Close),function(y) log(IPC$Close[y])-log(IPC$Close[x])))
t2 <-outer(log(IPC$Close), log(IPC$Close), FUN = "-")
# test case on simplier case
a=seq(1,5)
# both of the function below wll compute all the lags
# sapply, since lapply will output listed which require more processing
sapply(a, function(x) sapply(a, function(y) x-y)) 
outer(a, a, "-") 
# [,1] [,2] [,3] [,4] [,5]
# [1,]    0    1    2    3    4
# [2,]   -1    0    1    2    3
# [3,]   -2   -1    0    1    2
# [4,]   -3   -2   -1    0    1
# [5,]   -4   -3   -2   -1    0
but you should really look into time series(zoo, xts) and its respective functions such as lag() if you are really dealing with stock prices. Although I find it harder to work with sometimes.