Based on the discussion in Josh O'Brien's answer, the best way to do this now is setDF since it avoids copying. (This, of course, assumes that you do not need both the data.frame version and the data.table version of your data):
library(data.table) x <- data.table(a=1:4, b=letters[c(1,1,2,2)], key="a") setDF(x)
Michael
source share