Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法从data.frame中删除行_R_Excel_Dataframe - Fatal编程技术网

无法从data.frame中删除行

无法从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 =

我有一系列excel文件,很长一段时间以来,我一直在使用这些基本代码导入数据。我没有对数据或代码进行任何更改,但我不再正确读取数据。我阅读了以下文件:

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)', ]