我有一个数据集,我需要保留所有内容,除非ETA
为“5个工作日”,“8个工作日”为2个Booking Date
仅限“10月30日”和“10月31日” 。我很确定这将涉及grep函数,但我不知道如何使用这些条件。
我的原始数据集有14列,其中包含更多变量,但这里有一个样本....
任何帮助表示赞赏:)
DF
Booking Date ETA Address
8th October 4 business days 1 Lane Drive
30th October 5 business days 2 Daisy Rd
31st October 1 business day 5 Bay St
31st October 8 business days 10 Charlotte St
答案 0 :(得分:0)
希望这有帮助!
library(dplyr)
df %>%
filter(!(Booking_Date %in% c('30th October','31st October') &
ETA %in% c('5 business days','8 business days')))
输出是:
Booking_Date ETA Address
1 8th October 4 business days 1 Lane Drive
2 31st October 1 business day 5 Bay St
#sample data
> dput(df)
structure(list(Booking_Date = structure(c(3L, 1L, 2L, 2L), .Label = c("30th October",
"31st October", "8th October"), class = "factor"), ETA = structure(c(2L,
3L, 1L, 4L), .Label = c("1 business day", "4 business days",
"5 business days", "8 business days"), class = "factor"), Address = structure(c(1L,
3L, 4L, 2L), .Label = c("1 Lane Drive", "10 Charlotte St", "2 Daisy Rd",
"5 Bay St"), class = "factor")), .Names = c("Booking_Date", "ETA",
"Address"), class = "data.frame", row.names = c(NA, -4L))