Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

r

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.

like image 853
hcacode Avatar asked Nov 26 '25 03:11

hcacode


2 Answers

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
like image 85
Sotos Avatar answered Nov 27 '25 17:11

Sotos


Try:

tibble(x = c(123, 4232, 312, 321)) %>% 
  filter(!grepl("^1", x))
like image 22
mnist Avatar answered Nov 27 '25 17:11

mnist