Search code examples
rintegerr-factor

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


Solution

  • Easier than you think.

    List[!ok]