开发者

R: remove data in a logical variable using a factor variable

I made the following example code to give you an idea of my real dataset. I have 2 datasets, a factor variable List and a logical variable ok.

df1 <- c("a","b","c","d","e","f","g")
df2 <- c("a","d","e")
List <- factor(as.integer(df1 %in% df2))
ok <- c(TRUE,FALSE, FALSE,FALSE,TRUE,FALSE,TRUE)

The List and the ok variables has both a length of 7. I want to remove all the samples in List with the condition TRUE in ok. For example: the first, fifth and seventh variables need to be removed in the List variable.

Can anyone help me with this?

开发者_如何转开发

Thanks


Easier than you think.

List[!ok]


Perhaps List[!ok]? BTW, you don't need as.logical as vector ok will be saved internaly as logical.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜