I've been using R for a while now, but find myself using those things over and over again. I guess there must be an easier way than to write:
filtered <- names(table(col))[!match.something(names(table(col)))]
Where match.something returns an T/F-list.
Of course I could do the following to make it more concise and remove some duplication:
x <- names(table(col))
filtered <- x[!match.something(x)]
But it still feels like there should be a different/easier way to select like this. Something like subset(x, fun), to avoid having to type "x" twice. Which function am I looking for?
Example:
> col <- c("AA", "AA", "GG", "GG", "AA", "AG")
> x <- names(table(col))
> x[match.bases(x)]
[1] "AA" "GG"
This is the function I'm using right now:
BASES = c("AA", "GG", "CC", "TT")
match.bases <- function(df) {
df %in% BASES
}