【发布时间】:2022-12-01 07:06:35
【问题描述】:
这里发生了什么,设置顺序的应用导致原始选项卡具有否列未排序,而其他列是,从而 corrputing 数据表?
library(data.table)
library(purrr)
colFun <- function(dt, cols, fun){
for(col in cols){
dt[[col]] <- dt[[col]] %>% fun()
}
# irrelevant manipulations
return(dt)
}
topRows <- function(dt, n, ncol = 'N'){
setorderv(dt, ncol, -1)
# irrelevant manipulations
return(dt[1:n,])
}
tab <- data.table(
id = 1005:1001,
N = 1:5+.01,
X = c('E','D','C','B','A')
)
tab
#setkey(tab, id)
tab %>% colFun('N', round) %>% topRows(3)
tab
设置密钥时不会发生...
【问题讨论】:
标签: r data.table