我有各种列的数据,比如A,B,C,Cq,D,Dq,F,Fq,M,Mq,...,X。我希望每当列X的值> 200时,所有列的特定行都应该被删除。我的R代码如下。请大家帮忙修改一下代码。另外,我不确定是否应该将此条件放在col_names中或merged上?
col_names <- function(dt_list){
lapply(dt_list, FUN = function(x){
if ("ABq" %in% colnames(x)) {
x[ABq != 0, AB := NA]
x[AB < 10 | DIF > 100, AB := NA]
}
if ("MNq" %in% colnames(x)) {
x[MNq != 0, MN := NA]
x[MN < 25 | MN > 150, MN := NA]
}
return(x)
})
}
for (idx in seq_along(dirlist)){
filelist <- list.files(path = dirlist[idx], full.names = TRUE, recursive = TRUE, pattern =
".txt$")
dt_ <- read_the_files(filelist)
dt.tidied <- col_names(dt_)
#bind, filling missing columns to NA
merged <- rbindlist(dt.tidied, fill = TRUE, use.names = TRUE)
1条答案
按热度按时间8hhllhi21#
我相信解决办法很简单:
假设
dt_
是 Dataframe 的名称。沃伊拉