I have data with various columns for say A, B, C, Cq, D, Dq, F, Fq, M, Mq, ..., X. I want that whenever column X has value > 200, that particular row for all the columns should be removed. My code in R is as below. Could anyone please help me in modifying the code accordingly. Also, I am not sure if I should put this condition in col_names or on 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)
Update: dt_ is a large list, not a dataframe.