You just need to convert the return value of Delt
to a simple vector:
DT[,
paste('returns',LETTERS[1:2],sep=''):=lapply(.SD,function(x) c(Delt(x))),
by=ticker,.SDcols=grep('^price',names(DT))
]
This produces:
ticker priceA priceB returnsA returnsB
1: a 0.9148060 0.7956245 NA NA
2: a 0.9370754 0.9314941 0.02434327 0.1707710
3: a 0.2861395 0.6269996 -0.69464620 -0.3268883
4: a 0.8304476 0.1666758 1.90224707 -0.7341691
5: a 0.6417455 0.6483800 -0.22722939 2.8900659
---