data.table中的setnames确实会正确标记列

时间:2019-04-14 12:45:28

标签: r data.table

我得到以下结果:

meanIndi<-c(5.73, 5.90, 5.71, 5.70, 5.57, 5.80, 5.87, 5.58, 5.54, 5.78, 5.72)

varianceI<-c(0.016, 0.017, 0.029, 0.022, 0.021, 0.050, 0.027, 0.024, 0.021, 0.016, 0.037)

precisionI<-c(62.319, 60.014, 34.861, 44.695, 47.599, 19.915, 36.760, 42.543, 47.259, 61.025, 27.343)

我创建DataFrame如下:

library(data.table)
combinedData<-as.data.frame(meanIndi)
combinedData$variance <-as.data.frame(varianceI)
combinedData$precision<-as.data.frame(precisionI)
combinedData$beta<-as.data.frame(round(combinedData$variance/combinedData$meanIndi, 4))


setnames(combinedData, old = c("meanIndi", "variance", "precision", "beta"),
  new= c("sampleMean", "sampleVariance", "samplePrecision", "beta"))

当我打印combinedData时,看不到更新的列名。我看到列名为meanIndi, varianceI, precisionI, varianceI。如何使它看起来像sampleMean, sampleVariance, samplePrecision, beta

0 个答案:

没有答案