Filter dataframe with NA by a column condition in r

时间:2019-05-31 11:30:33

标签: r

I have a dataframe :

df <- data.frame( Date = c("2017-02-23", "2017-02-23", "2017-02-24", "2017-02-24", "2017-02-25", "2017-02-25", "2017-02-25"),
                     var = c(2, NA, 1, 1,1, 7, 4))

I want to filter by date where var == 7

I tried with:

df %>% filter(Date[var  == 7])

But there is an error: Argument 2 filter condition does not evaluate to a logical vector

What is wrong with this code?

1 个答案:

答案 0 :(得分:0)

You can use dplyr package

> df %>% filter(var == 7)

        Date  var
 1 2017-02-25   7
相关问题