dplyr:根据两列删除值

时间:2016-06-05 05:02:03

标签: r dplyr

使用df

date <- c(rep(as.Date("2003-01-05"), 5), rep(as.Date("2004-01-05"), 5), rep(as.Date("2005-01-05"), 5), rep(as.Date("2006-01-05"), 5))
parameter <- rep(c("param_A", "param_B", "param_C", "param_D", "param_E"), 4)

df <- data.frame(date, parameter)
df$year <- year(df$date)

如何删除param_A的{​​{1}},但保留所有其他年份?

1 个答案:

答案 0 :(得分:5)

我们可以尝试filter

df %>% 
    filter(!(parameter=="param_A" & year == 2003))