How to delete entire row if my specified column value starts with '1'

Viewed 81

I have a dataset:

yearID  teamID  lgID  playerID   salary
 1985    BAL     AL   murraed02  1472819
 1985    BAL     AL   lynnfr01   1090000
 1985    BAL     AL   ripkeca01  800000
 1985    BAL     AL   lacyle01   725000
 1985    BAL     AL   flanami01  641667
 1985    BAL     AL   boddimi01  625000
 1985    BAL     AL   stewasa01  581250

I'd like to delete an entire row if the salary column value starts with '1'.

For instance, if the salary column value is 12240, I'd like to remove the row.

3 Answers

Try:

tibble(x = c(123, 4232, 312, 321)) %>% 
  filter(!grepl("^1", x))

Here is a fun idea with math,

df[df$salary / 10^(nchar(df$salary)) >= 0.2,]

#  yearID teamID lgID  playerID salary
#3   1985    BAL   AL ripkeca01 800000
#4   1985    BAL   AL  lacyle01 725000
#5   1985    BAL   AL flanami01 641667
#6   1985    BAL   AL boddimi01 625000
#7   1985    BAL   AL stewasa01 581250
df[!stringr::str_extract(df$salary, "\\d{1}")==1,]

  yearID teamID lgID  playerID salary
3   1985    BAL   AL ripkeca01 800000
4   1985    BAL   AL  lacyle01 725000
5   1985    BAL   AL flanami01 641667
6   1985    BAL   AL boddimi01 625000
7   1985    BAL   AL stewasa01 581250
Related