无法从data.frame中删除行
我有一系列excel文件,很长一段时间以来,我一直在使用这些基本代码导入数据。我没有对数据或代码进行任何更改,但我不再正确读取数据。我阅读了以下文件:无法从data.frame中删除行,r,excel,dataframe,R,Excel,Dataframe,我有一系列excel文件,很长一段时间以来,我一直在使用这些基本代码导入数据。我没有对数据或代码进行任何更改,但我不再正确读取数据。我阅读了以下文件: apply_fun <- function(filename) { data <- readxl::read_excel(filename, sheet = "Section Cut Forces - Design", skip = 1, col_names =
apply_fun <- function(filename) {
data <- readxl::read_excel(filename, sheet = "Section Cut Forces - Design",
skip = 1, col_names = TRUE)
data <- data[-1,]
data <- subset(data, StepType == "Max")
data <- data[,c(1,2,6,10)]
data$id <- filename
return(data)
}
filenames <- list.files(pattern = "\\.xlsx", full.names = TRUE)
first <- lapply(filenames,apply_fun)
out <- do.call(rbind,first)
我尝试删除行,如下所示:
out2 <- out[!grep("Service (after losses)", out$OutputCase),]
out2()
是正则表达式中的特殊符号。当您在grep
/grepl
等函数中使用它们时,它们具有特殊的意义。您可以在grep
中使用fixed=TRUE
来精确匹配它们。还有
应与grepl
一起使用,-
应与grep
一起使用以删除行
out[-grep("Service (after losses)", out$OutputCase, fixed = TRUE),]
除此之外,这看起来像是一个精确的匹配,那么为什么要将模式匹配与grep
一起使用呢?尝试:
out[out$OutputCase != 'Service (after losses)', ]
out[out$OutputCase != 'Service (after losses)', ]