删除给定条件向量的行 - R.

时间:2018-05-15 01:41:52

标签: r filter conditional slice

鉴于此df:

//assume you have read the json string from a file and use it as following
const json_string = `{
    "VARIABLE_YES":"Yes",
    "VARIABLE_NO":"No"
}`;

const json_obj = JSON.parse(json_string);
builder.Prompts.choice(session, 'Make a choice', [json_obj.VARIABLE_YES, json_obj.VARIABLE_NO], {
    listStyle: builder.ListStyle.button
});

定义为匹配删除的值位于向量中:

   A B  C
1  a 1 53
2  a 0 27
3  a 1 46
4  b 1 42
5  c 0 97
6  d 1 46
7  d 0 24

如何使用带向量的条件删除values_delete <- c("b", "c") 中的行?我试过了:

df

但它并不允许。这是错误:

df2 <- df[df$A != values_delete,]

1 个答案:

答案 0 :(得分:1)

请参阅%in%的{​​{3}}

df2 <- df[!(df$A %in% values_delete), ]