How to specify “does not contain” in dplyr filter

前端 未结 2 1927
予麋鹿
予麋鹿 2020-12-08 02:27

I am quite new to R.

Using the table called SE_CSVLinelist_clean, I want to extract the rows where the Variable called where_case_travelled_1

2条回答
  •  眼角桃花
    2020-12-08 02:59

    Note that %in% returns a logical vector of TRUE and FALSE. To negate it, you can use ! in front of the logical statement:

    SE_CSVLinelist_filtered <- filter(SE_CSVLinelist_clean, 
     !where_case_travelled_1 %in% 
       c('Outside Canada','Outside province/territory of residence but within Canada'))
    

    Regarding your original approach with -c(...), - is a unary operator that "performs arithmetic on numeric or complex vectors (or objects which can be coerced to them)" (from help("-")). Since you are dealing with a character vector that cannot be coerced to numeric or complex, you cannot use -.

提交回复
热议问题