When using `data.table`'s DT[ i , j, by], is it possible to set the column types before hand?
问题 I'm trying to calculating the correlation between two variables for multiple different groups (e.g. DT[, cor.test(var1, var2), group] ). This works great whenever I use cor.test(var1, var2, method = 'pearson') but throws an error when I use cor.test(var1, var2, method = 'spearman') . library(data.table) DT <- as.data.table(iris) # works perfectly DT[,cor.test(Sepal.Length,Sepal.Width, method = 'pearson'), Species] # Species statistic parameter p.value estimate null.value # 1: setosa 7.680738