How to remove entire row if one row begins with a certain value.

Hi!

I need help removing an entire row if one specific row begins with a certain value. Example: order numbers (character value) begin with either 1 or 4 and I need to remove all of the order numbers that begin with 1. But, I need to remove the entire row of information, not just the values that begin with 1 in that column .

order number Location Date
1234- x 1/29
4567- y 1/29
4910- z 1/29

I want the output to be :
order number Location Date
4567- y 1/29
4910- z 1/29

The filter function of dplyr is handy for this.

library(tibble)
#> Warning: package 'tibble' was built under R version 4.1.2
library(dplyr)
library(stringr)
DF <- tribble(
  ~order_number, ~Location, ~Date,
  "1234-", "x", "1/29",
"4567-", "y", "1/29",
"4910-", "z", "1/29")
DF
#> # A tibble: 3 x 3
#>   order_number Location Date 
#>   <chr>        <chr>    <chr>
#> 1 1234-        x        1/29 
#> 2 4567-        y        1/29 
#> 3 4910-        z        1/29
DF <- DF |> filter(str_sub(string = order_number, start = 1,end = 1) != "1")
DF
#> # A tibble: 2 x 3
#>   order_number Location Date 
#>   <chr>        <chr>    <chr>
#> 1 4567-        y        1/29 
#> 2 4910-        z        1/29

Created on 2022-01-29 by the reprex package (v2.0.1)

This worked perfectly thank you! I was able to pass in the date frame without having to change it: df <- df %>% filter(str_sub(string = df$ordernumber, start = 1, end = 1) != 1)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.