[Solved] Deleting specific rows with a pattern[start and end indicators] from a dataframe [closed]


Using a toy example…

df <- data.frame(a=LETTERS[1:10],b=LETTERS[3:12],stringsAsFactors = FALSE)
limits <- c("E","H")

sapply(df,function(x){
  del.min <- grep(limits[1],x)
  del.max <- grep(limits[2],x)
  x[del.min:del.max] <- ""
  return(x)})

      a   b  
 [1,] "A" "C"
 [2,] "B" "D"
 [3,] "C" "" 
 [4,] "D" "" 
 [5,] ""  "" 
 [6,] ""  "" 
 [7,] ""  "I"
 [8,] ""  "J"
 [9,] "I" "K"
[10,] "J" "L"

4

solved Deleting specific rows with a pattern[start and end indicators] from a dataframe [closed]