我有一个数据集:
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
如果salary
列值以'1'开头,我想删除整行。
例如,如果salary
列的值为12240
,我想删除该行。
答案 0 :(得分:3)
尝试:
tibble(x = c(123, 4232, 312, 321)) %>%
filter(!grepl("^1", x))
答案 1 :(得分:3)
这是一个关于数学的有趣主意,
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
答案 2 :(得分:2)
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