Q:

R: Remove dataframe elements that contain a specific character

A dataframe includes strings that contain a specific character (such as “<”): 
DF <- data.frame(c(1,"<2",3),c("< 4",5,6),c(7,8,"<"),stringsAsFactors = FALSE)

I want to remove (e.g. convert to NA) those elements that contain the character “<”. I could do this by columns or rows with grep(). Can this be done in the whole dataframe at once? (one liner preferred)

A:

The one-liner given by @Ronak in his comment above may be the easiest and most graceful way to proceed here.  That being said, if you need to search for specific strings to replace with NA, then here is base R option:
data.frame(lapply(DF, function(x) { ifelse(grepl(".*<.*", x), NA, x) }))

This would replace each entry in the data frame containing < anywhere with NA, and you can easily extend to handle any pattern as it uses grepl.

